Skip to content

Instantly share code, notes, and snippets.

@Soupala
Soupala / global-variables-are-bad.js
Created May 6, 2016 16:31 — forked from hallettj/global-variables-are-bad.js
How and why to avoid global variables in JavaScript
// It is important to declare your variables.
(function() {
var foo = 'Hello, world!';
print(foo); //=> Hello, world!
})();
// Because if you don't, the become global variables.
(function() {
@Soupala
Soupala / README.md
Last active August 29, 2015 14:27 — forked from nitaku/README.md
Graph editing tools

Starting from the previous example, this one implements a more complete graph editing tool.

Select a tool to operate on the graph: The pointer only lets the user pan & zoom or drag nodes around. The add node tool opens up a library of node types; click one to add a node of that type to the graph. The add link tool lets the user connect two nodes with a drag gesture from the first to the second one.

Clicking a node or a link always selects it regardless of the current tool. You can press del to remove the current selection.

The example activates and deactivates d3.js's drag behavior on nodes by using a technique found in this example by Ross Kirsling: Everytime the behavior has to be deactivated, the underlying listeners (mousedown.drag and touchstart.drag) are cleared.

Mouse coordinates are used to move the representation of a new link. The coordinates are retrieved as in [this example]

@Soupala
Soupala / README.md
Last active August 29, 2015 14:27 — forked from nitaku/README.md
Graph editing with persistence

Same as the previous example, but with client-side persistence, thanks to the IndexedDB APIs (see this other example).

Try to modify the graph, then reload the page to load it again.

The graph is automatically saved on each modification of its structure, and also every second with a setInterval, to store even the changes made to nodes' position by the force layout.

Keybase proof

I hereby claim:

  • I am soupala on github.
  • I am soupala (https://keybase.io/soupala) on keybase.
  • I have a public key whose fingerprint is 1B62 1F6D 98DE 702B 19E2 9849 EDCF D4D7 6886 BAFC

To claim this, I am signing this object:

@Soupala
Soupala / base64.js
Last active August 29, 2015 14:15 — forked from whatnickcodes/base64.js
// Create Base64 Object
var Base64={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encode:function(e){var t="";var n,r,i,s,o,u,a;var f=0;e=Base64._utf8_encode(e);while(f<e.length){n=e.charCodeAt(f++);r=e.charCodeAt(f++);i=e.charCodeAt(f++);s=n>>2;o=(n&3)<<4|r>>4;u=(r&15)<<2|i>>6;a=i&63;if(isNaN(r)){u=a=64}else if(isNaN(i)){a=64}t=t+this._keyStr.charAt(s)+this._keyStr.charAt(o)+this._keyStr.charAt(u)+this._keyStr.charAt(a)}return t},decode:function(e){var t="";var n,r,i;var s,o,u,a;var f=0;e=e.replace(/[^A-Za-z0-9\+\/\=]/g,"");while(f<e.length){s=this._keyStr.indexOf(e.charAt(f++));o=this._keyStr.indexOf(e.charAt(f++));u=this._keyStr.indexOf(e.charAt(f++));a=this._keyStr.indexOf(e.charAt(f++));n=s<<2|o>>4;r=(o&15)<<4|u>>2;i=(u&3)<<6|a;t=t+String.fromCharCode(n);if(u!=64){t=t+String.fromCharCode(r)}if(a!=64){t=t+String.fromCharCode(i)}}t=Base64._utf8_decode(t);return t},_utf8_encode:function(e){e=e.replace(/\r\n/g,"\n");var t="";for(var n=0;n<e.length;n++){var r=e.charCodeAt(n);if(r
# ps -ef - disaply all processes
# grep apache2 - find the rows with apache
# grep -v grep - remove rows with the word grep
# awk '{print $2}' - get the second column of the previous output
# kill -9 $(..) - execute kill -9 on all the values returned from the previous pipes
kill -9 $(ps -ef |grep apache2 |grep -v grep| awk '{print $2}')
#301 Redirects for .htaccess
#Redirect a single page:
Redirect 301 /pagename.php http://www.domain.com/pagename.html
#Redirect an entire site:
Redirect 301 / http://www.domain.com/
#Redirect an entire site to a sub folder
Redirect 301 / http://www.domain.com/subfolder/
#!/bin/bash
#
# Use this script to perform backups on one or more MySQL databases.
#
# Databases that you wish to be backed up by this script. You can have any number of databases specified; encapsilate each database name in single quotes and separate each database name by a space.
#
# Example:
# databases=( '__DATABASE_1__' '__DATABASE_2__' )
@Soupala
Soupala / rotatetext
Created February 1, 2014 18:22
A simple jQuery pattern for rotation through a series of html elements. Kind of like a carousel, but just for text or other overlays.
(function() {
var rotates = $(".rotatetext");
var rotateIndex = -1;
function showNextRotate() {
++rotateIndex;
rotates.eq(rotateIndex % rotates.length)
.fadeIn(900)
.delay(1800)