working on it ...
Explore Public Snippets
Found 390k snippets
NEW_NAME="NewName" NEW_OTP="new_name" ack -l $CURRENT_NAME | xargs sed -i '' -e "s/$CURRENT_NAME/$NEW_NAME/g" ack -l $CURRENT_OTP | xargs sed -i '' -e "s/$CURRENT_OTP/$NEW_OTP/g"
NEW_NAME="NewName" NEW_OTP="new_name" ack -l $CURRENT_NAME | xargs sed -i '' -e "s/$CURRENT_NAME/$NEW_NAME/g" ack -l $CURRENT_OTP | xargs sed -i '' -e "s/$CURRENT_OTP/$NEW_OTP/g"
public by ronrihoo 1614 0 6 1
Getting the screen size with libGDX
Along with some other screen analysis methods.
import com.badlogic.gdx.Gdx; import java.lang.Math; public class ScreenDetails { // ... /** * * @return Total count of pixels (height * width). */ private double getResolution() { return Gdx.graphics.getHeight() * Gdx.graphics.getWidth(); } /** * * @return PPI (Pixels Per Inch). */ private float getDensity() { return Gdx.graphics.getPpiX(); } /** * * @return Horizontal pixel count, squared. */ private double getWidthSquared() { return Math.pow(Gdx.graphics.getWidth(), 2); } /** * * @return Vertical pixel count, squared. */ private double getHeightSquared() { return Math.pow(Gdx.graphics.getHeight(), 2); } /** * * @return Approximate screen size or size of app on screen (diameter in inches). */ private double getScreenSize() { return (Math.sqrt(getWidthSquared() + getHeightSquared()) / getDensity()); } }
public by kannuPriya 581 2 5 0
jQuery ready() Method
The ready event occurs when the DOM (document object model) has been loaded.
The ready() method specifies what happens when a ready event occurs.
$(document).ready(function(){ });
public by ronrihoo 1806 5 7 1
Example helper class for GDXFacebook
This helper class simplifies the usage of GDXFacebook in libGDX games and apps. (This is a backup to https://github.com/ronrihoo/GDX-Facebook-API-Helper and it's used in https://stackoverflow.com/a/46230835/6664817)
// add package here import com.badlogic.gdx.Application; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.utils.Array; import de.tomgrill.gdxfacebook.core.*; public class FacebookApi { private final static String CLASS_NAME = FacebookApi.class.getSimpleName(); private final static String ERR_IN = "Error: in " + CLASS_NAME; private final static String EXC_IN = "Exception: in " + CLASS_NAME; private final static boolean VERBOSE_DEFAULT = true; private final static boolean DEBUG_DEFAULT = true; private boolean verbose; private boolean debug; private Array<String> permissions; private GDXFacebookConfig config; private GDXFacebook facebook; private GDXFacebookAccessToken token; /* if there's a class where credentials are stored or retrieved from, * then a constructor like this one could be used */ /* public FacebookApi() { this(Credentials.FB_API_ID); } /**/ public FacebookApi(String appId) { this(appId, null, null); } /** * * @param appId The Facebook API ID is required. * @param prefFilename Optional (example: ".facebookSessionData"). * @param apiVersion Optional. Graph API Version (default: v2.6). */ public FacebookApi(String appId, String prefFilename, String apiVersion) { init(appId, prefFilename, apiVersion, DEBUG_DEFAULT); } private void init(String appId, String prefFilename, String apiVersion, boolean debug) { setVerbose(VERBOSE_DEFAULT); setDebug(debug); if (appId != null) { setAppId(appId); } else { try { throw new RuntimeException(EXC_IN + ".init(...): appId is null. Has it been passed correctly?"); } catch (Exception e) { e.printStackTrace(); } } if (prefFilename != null) setPrefFilename(prefFilename); if (apiVersion != null) setGraphApiVersion(apiVersion); initPermissionsArray(); installGdxFacebookInstance(); setGdxFacebookInstance(); addBasicPermissions(); } private void setGdxDebug(boolean debug) { debugLog("setGdxDebug(boolean debug)"); if (debug) Gdx.app.setLogLevel(Application.LOG_DEBUG); // TODO: turn it off when debug == false } private void instantiateConfig() { debugLog("instantiateConfig()"); config = new GDXFacebookConfig(); } private boolean verifyConfig() { debugLog("verifyConfig()"); if (config == null) { try { instantiateConfig(); } catch (Exception e) { System.out.println(EXC_IN + ".verifyConfig(): \n" + e); return false; } } return true; } private void setAppId(String appId) { debugLog("setAppId(String appId)"); if (verifyConfig()) config.APP_ID = appId; } private void setPrefFilename(String filename) { debugLog("setPrefFilename(String filename)"); if (verifyConfig()) config.PREF_FILENAME = filename; } private void setGraphApiVersion(String version) { debugLog("setGraphApiVersion(String version)"); if (verifyConfig()) config.GRAPH_API_VERSION = version; } private void installGdxFacebookInstance() { debugLog("installGdxFacebookInstance()"); if (verifyConfig()) facebook = GDXFacebookSystem.install(config); } /** * No parameters, as it is handled by GDXFacebookSystem */ public void setGdxFacebookInstance() { debugLog("setGdxFacebookInstance()"); if (facebook != null) facebook = GDXFacebookSystem.getFacebook(); } /** * * @return GDXFacebook object. */ public GDXFacebook getGdxFacebookInstance() { debugLog("getGdxFacebookInstance()"); return facebook; } private void initPermissionsArray() { debugLog("initPermissionsArray()"); permissions = new Array<String>(); } private void addBasicPermissions() { debugLog("addBasicPermissions()"); permissions.add("email"); permissions.add("public_profile"); permissions.add("user_friends"); } public void addPermission(String permission) { debugLog("addPermission(String)"); if (permissions != null) permissions.add(permission); else System.out.println(ERR_IN + ": permissions array is null"); } /** * Basic sign-in with read-mode */ public void signIn() { debugLog("signIn()"); signIn(SignInMode.READ); } public void signIn(SignInMode signInMode) { debugLog("signIn(SignInMode)"); if (facebook != null) { if (permissions == null) { addBasicPermissions(); debug(CLASS_NAME + ": returned to signIn(SignInMode) from addBasicPermissions()"); } facebook.signIn(signInMode, permissions, new GDXFacebookCallback<SignInResult>() { @Override public void onSuccess(SignInResult result) { if (verbose) System.out.println("Successfully signed in Facebook."); token = result.getAccessToken(); debug(CLASS_NAME + ".signIn() succeeded."); debug(CLASS_NAME + ": accessToken is " + token); } @Override public void onError(GDXFacebookError error) { if (debug) System.out.println(ERR_IN + ".signIn(): " + error.getErrorMessage()); debug("signIn() invoked by GDXFacebook instance, facebook, in " + CLASS_NAME + " faced an error."); } @Override public void onCancel() { // When the user cancels the login process debug("signIn() invoked by GDXFacebook instance, facebook, in " + CLASS_NAME + " canceled."); } @Override public void onFail(Throwable t) { // When the login fails debug("signIn() invoked by GDXFacebook instance, facebook, in " + CLASS_NAME + " failed."); } }); } else { debug(ERR_IN + ".signIn(): " + "GDXFacebook instance, facebook, is null."); } } public void signOut() { debug(CLASS_NAME + ".signOut()"); facebook.signOut(); } protected void setVerbose(boolean verbose) { this.verbose = verbose; } protected void setDebug(boolean debug) { this.debug = debug; setGdxDebug(debug); } private void debug(String msg) { if (debug) System.out.println(msg); } private void debugLog(String methodName) { if (verbose) debug(CLASS_NAME + "." + methodName); } }
// Enter here the actual content of the snippet. <!DOCTYPE HTML> <html> <head> <title>Ensighten Test Site</title> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <meta name="description" content="" /> <meta name="keywords" content="" /> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,minimum-scale=1"> <!--<script type="text/javascript" src="js/Bootstrap.js"></script>--> <!--<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script src="js/skel.min.js"></script> <script src="js/skel-panels.min.js"></script> <script src="js/init.js"></script>--> <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Tangerine"> <link rel="stylesheet" href="css/style.css" /> <link rel="stylesheetz" href="css/style-desktop.css" /> <link rel="canonical" href="/ensighten-luka-test.eu.pn/left-sidebar.html"> <script type="text/javascript" src="//nexus.ensighten.com/ens-devtech/luka/Bootstrap.js"></script> <script async src="https://cdn.ampproject.org/v0.js"></script> <style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript> <meta name="amp-google-client-id-api" content="googleanalytics"> </head> <body class="homepage"> <!-- <div id="fbAds"></div> <figure></figure> --> <!-- Header --> <div id="header"> <div id="nav-wrapper"> <!-- Nav --> <nav id="nav"> <ul> <li class="active"><a href="index.html?adxcel_clickid=34re4">Homepage</a></li> <li><a href="left-sidebar.html" id="button">Left Sidebar</a></li> <li><a href="right-sidebar.html">Right Sidebar</a></li> <li><a href="no-sidebar.html">No Sidebar</a></li> </ul> </nav> </div> <div class="container"> <!-- Logo --> <div id="logo"> <h1><•></h1> <span class="tag">SandBox</span> </div> </div> </div> <!-- Featured --> <div id="featured"> <div class="container"> <header> <h2>Welcome to SandBox test site</h2> </header> <p>This site is used by DevApps team for testing and presentation purpose.</p> <hr /> <div class="row"> <div id="test"> </div> <section class="4u"> <h3>Maecenas luctus lectus</h3> <p>Curabitur sit amet nulla. Nam in massa. Sed vel tellus. Curabitur sem urna, consequat vel, suscipit in, mattis placerat, nulla. Sed ac leo.</p> <a href="#" class="button button-style1">Read More</a> </section> <section class="4u"> <h3>Maecenas luctus lectus</h3> <p>Donec ornare neque ac sem. Mauris aliquet. Aliquam sem leo, vulputate sed, convallis at, ultricies quis, justo. Donec magna.</p> <a href="#" class="button button-style1">Read More</a> </section> <section class="4u"> <h3>Maecenas luctus lectus</h3> <p>Curabitur sit amet nulla. Nam in massa. Sed vel tellus. Curabitur sem urna, consequat vel, suscipit in, mattis placerat, nulla. Sed ac leo.</p> <a href="#" class="button button-style1">Read More</a> </section> </div> </div> </div> <!-- Main --> <div id="main"> <div id="content" class="container"> <div class="row"> <section class="6u"> <header> <h2>Mauris vulputate dolor</h2> </header> <p>In posuere eleifend odio. Quisque semper augue mattis wisi. Maecenas ligula. Pellentesque viverra vulputate enim. Aliquam erat volutpat. Donec leo, vivamus fermentum nibh in augue praesent a lacus at urna congue rutrum.</p> </section> <section class="6u"> <header> <h2>Mauris vulputate dolor</h2> </header> <p>In posuere eleifend odio. Quisque semper augue mattis wisi. Maecenas ligula. Pellentesque viverra vulputate enim. Aliquam erat volutpat. Donec leo, vivamus fermentum nibh in augue praesent a lacus at urna congue rutrum.</p> </section> </div> <div class="row"> <section class="6u"> <header> <h2>Mauris vulputate dolor</h2> </header> <p>In posuere eleifend odio. Quisque semper augue mattis wisi. Maecenas ligula. Pellentesque viverra vulputate enim. Aliquam erat volutpat. Donec leo, vivamus fermentum nibh in augue praesent a lacus at urna congue rutrum.</p> </section> <section class="6u"> <header> <h2>Mauris vulputate dolor</h2> </header> <p>In posuere eleifend odio. Quisque semper augue mattis wisi. Maecenas ligula. Pellentesque viverra vulputate enim. Aliquam erat volutpat. Donec leo, vivamus fermentum nibh in augue praesent a lacus at urna congue rutrum.</p> </section> </div> </div> </div> <!-- Tweet --> <div id="tweet"> <div class="container"> <section> <blockquote>“In posuere eleifend odio. Quisque semper augue mattis wisi. Maecenas ligula. Pellentesque viverra vulputate enim. Aliquam erat volutpat.”</blockquote> </section> </div> </div> <!-- Footer --> <div id="footer"> <div class="container"> <section> <header> <h2>Maecenas ligula</h2> <span class="byline">Integer sit amet pede vel arcu aliquet pretium</span> </header> </section> </div> </div> <!-- Copyright --> <div id="copyright"> <div class="container"> Design: <a href="http://templated.co">TEMPLATED</a> Images: <a href="http://unsplash.com">Unsplash</a> (<a href="http://unsplash.com/cc0">CC0</a>) </div> </div> </body> </html>
public by yourfriendcaspian 486 0 3 0
Install Mysql with Python and Django Debian/Derivatives - Translated
Install Mysql with Python and Django Debian/Derivatives - Translated:
mysql_python_on_debian.txt
#Install Mysql with Python and Django Debian/Derivatives #To install we need to have some dependencies in the system for now we will show on #Debian and Derivatives. #But first install updates and MySQL ``` $ sudo apt-get update $ sudo apt-get upgrade ``` # ** NOTE: ** #Each System has its commands for updating, if your machine is not derived from Debian ** look for them ** ##Install MySQL ``` $ sudo apt-get install mysql-server mysql-client Passwd for 'root' user: <password> ``` #At the end we execute this command to give more security to our BD ``` $ mysql_secure_installation ``` #Check carefully the changes that will be made, the first question is the passwd for root, #IF you want to keep or change it, and continue with other security questions. ##Create a database and a user for the DB #Now we will create the DB that will be connected to DJango and a User with Passwd to access it. #There are two ways to do this: ``` echo "CREATE DATABASE <DATABASENAME>;" | mysql -u root -p echo "CREATE USER '<DATABASEUSER>'@'localhost' IDENTIFIED BY '<PASSWORD>';" | mysql -u root -p echo "GRANT ALL PRIVILEGES ON <DATABASENAME>.* TO '<DATABASEUSER>'@'localhost';" | mysql -u root -p echo "FLUSH PRIVILEGES;" | mysql -u root -p ``` #So they should put their passwd of mysql in each line or #they can also do it of the following way ``` $ mysql -u root -p ``` #Enter your passwd and then do the following. ``` CREATE DATABASE <DATABASENAME>; CREATE USER '<DATABASEUSER>'@localhost IDENTIFIED BY '<PASSWORD>'; GRANT ALL PRIVILEGES ON <DATABASENAME>.* TO '<DATABASEUSER>'@localhost; FLUSH PRIVILEGES; exit ``` #We Check Dependencies #There are only a few dependencies but you have to be sure ``` $ sudo apt-get install libmysqlclient-dev python-dev ``` #So far it's all just proceed to install pip in our virtual environment or globally ``` $ sudo -H pip install mysql-python ``` #As you can see now you can create DB and Users for each Django Project
public by yourfriendcaspian 426 1 3 0
Provision Ubuntu 16.04 Server
Provision Ubuntu 16.04 Server:
ubuntu_server_provision.txt
- Postgres sudo apt install postgresql move databases - Samba File Server https://help.ubuntu.com/lts/serverguide/samba-fileserver.html - Elastic Search https://www.digitalocean.com/community/tutorials/how-to-install-elasticsearch-on-an-ubuntu-vps sudo add-apt-repository ppa:webupd8team/java sudo apt install oracle-java8-installer wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.4.0.deb sudo dpkg -i elasticsearch-5.4.0.deb - Logstash wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add - echo "deb https://artifacts.elastic.co/packages/5.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-5.x.list sudo apt install logstash=1:5.4.0-1 sudo systemctl stop logstash sudo systemctl start logstash sudo systemctl enable logstash - Kibana https://www.elastic.co/guide/en/kibana/current/deb.html wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add - sudo apt-get install apt-transport-https echo "deb https://artifacts.elastic.co/packages/5.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-5.x.list sudo systemctl enable kibana -------------------- - Beats wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add - echo "deb https://artifacts.elastic.co/packages/5.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-5.x.list sudo apt-get update && sudo apt-get install filebeat # sudo update-rc.d filebeat defaults 95 10 - Mongo https://docs.mongodb.com/manual/administration/production-notes/#kernel-and-file-systems https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6 echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list sudo apt update apt cache madison mongodb-org sudo apt install mongodb-org=3.4.4 move databases ----------- - Neo4j https://neo4j.com/download/community-edition/ sudo wget https://neo4j.com/artifact.php?name=neo4j-community-3.2.0-unix.tar.gz https://www.digitalocean.com/community/tutorials/how-to-install-neo4j-on-an-ubuntu-vps wget -O - http://debian.neo4j.org/neotechnology.gpg.key | apt-key add - echo 'deb http://debian.neo4j.org/repo stable/' > /etc/apt/sources.list.d/neo4j.list sudo apt update apt-cache madison neo4j | head sudo apt install neo4j=3.2.0 ## nginx apt-cache madison nginx nginx | 1.10.0-0ubuntu0.16.04.4 | http://tr.archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages nginx | 1.10.0-0ubuntu0.16.04.4 | http://tr.archive.ubuntu.com/ubuntu xenial-updates/main i386 Packages nginx | 1.10.0-0ubuntu0.16.04.4 | http://security.ubuntu.com/ubuntu xenial-security/main amd64 Packages nginx | 1.10.0-0ubuntu0.16.04.4 | http://security.ubuntu.com/ubuntu xenial-security/main i386 Packages nginx | 1.9.15-0ubuntu1 | http://tr.archive.ubuntu.com/ubuntu xenial/main amd64 Packages nginx | 1.9.15-0ubuntu1 | http://tr.archive.ubuntu.com/ubuntu xenial/main i386 Packages apt install nginx=1.10.0-0ubuntu0.16.04.4 ---------------------------------------- - Docker https://docs.docker.com/engine/installation/linux/ubuntu/#install-using-the-repository ahmed@ubuntuserver:~$ apt-cache madison docker-ce docker-ce | 17.03.1~ce-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages docker-ce | 17.03.0~ce-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages sudo apt install docker-ce=17.03.1~ce-0~ubuntu-xenial - Docker Machine Host docker-machine create --driver none --url=tcp://192.168.1.21:2376 default docker-machine regenerate-certs default - KVM https://help.ubuntu.com/community/KVM/Installation sudo apt-get install qemu-kvm libvirt-bin ubuntu-vm-builder bridge-utils sudo apt-get install nmap sudo apt install python-setuptools sudo apt install python-pip - Influx Time Series DB docker pull telegraf:1.3-alpine wget https://dl.influxdata.com/telegraf/releases/telegraf_1.3.1-1_amd64.deb sudo dpkg -i telegraf_1.3.1-1_amd64.deb docker pull influxdb:1.2-alpine wget https://dl.influxdata.com/influxdb/releases/influxdb_1.2.4_amd64.deb sudo dpkg -i influxdb_1.2.4_amd64.deb docker pull quay.io/influxdb/chronograf:1.3.1.0 wget https://dl.influxdata.com/chronograf/releases/chronograf_1.3.1.0_amd64.deb sudo dpkg -i chronograf_1.3.1.0_amd64.deb docker pull kapacitor:1.3.1-alpine wget https://dl.influxdata.com/kapacitor/releases/kapacitor_1.3.1_amd64.deb sudo dpkg -i kapacitor_1.3.1_amd64.deb
public by yourfriendcaspian 465 6 4 0
Random Linux program install commands
Random Linux program install commands:
command_line_app_installs.txt
# Install Postgres http://apt.postgresql.org/pub/repos/apt/ 9.4-pgdg main wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - sudo apt-get update sudo apt-get install postgresql-9.4 # Install redis curl -O http://download.redis.io/releases/redis-3.2.9.tar.gz tar xzf redis-3.2.9.tar.gz rm redis-3.2.9.tar.gz make -C redis-3.2.9 # Install elasticsearch curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.4.1.tar.gz tar -xvf elasticsearch-5.4.1.tar.gz # Install Enpass #echo "Download Enpass"; #curl -O https://dl.sinew.in/linux/setup/5-5-3/Enpass_Installer_5.5.3 #chmod +x Enpass_Installer_5.5.3 #./Enpass_Installer_5.5.3 #rm Enpass_Installer_5.5.3 # Install oh-my-zsh sudo apt-get install zsh sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" # Install tmux sudo apt-get install tmux # Install Chrome #wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb #sudo dpkg -i google-chrome*.deb #Install dotfiles #\curl https://raw.githubusercontent.com/nandosousafr/dotfiles/master/bootstrap.sh | bash #Install ELEMENTARY tweaks #sudo add-apt-repository ppa:mpstark/elementary-tweaks-daily #sudo apt-get update #sudo apt-get install elementary-tweaks