Skip to content

Instantly share code, notes, and snippets.

View raphaelchaib's full-sized avatar

Raphael Chaib raphaelchaib

View GitHub Profile
@raphaelchaib
raphaelchaib / script.js
Created August 24, 2016 21:05
JavaScript: Detects what mouse button was used, left, right, middle, or middle scroll either direction
/**
Better Javascript Mouse Events
Author: Casey Childers
https://jsfiddle.net/BNefn/
**/
(function(){
// use addEvent cross-browser shim: https://gist.github.com/dciccale/5394590/
var addEvent = function(a,b,c){try{a.addEventListener(b,c,!1)}catch(d){a.attachEvent('on'+b,c)}};
/* This function detects what mouse button was used, left, right, middle, or middle scroll either direction */
@raphaelchaib
raphaelchaib / script.js
Created August 18, 2016 08:07
JavaScript: Get url parameters
var $_GET = {};
if(document.location.toString().indexOf('?') !== -1) {
var query = document.location
.toString()
// get the query string
.replace(/^.*?\?/, '')
// and remove any existing hash string (thanks, @vrijdenker)
.replace(/#.*$/, '')
.split('&');
@raphaelchaib
raphaelchaib / cp_p.sh
Created August 17, 2016 15:04
Shell Script: Show copy progress with "cp_p"
#!/bin/sh
cp_p()
{
strace -q -ewrite cp -- "${1}" "${2}" 2>&1 \
| awk '{
count += $NF
if (count % 10 == 0) {
percent = count / total_size * 100
printf "%3d%% [", percent
for (i=0;i<=percent;i++)
@raphaelchaib
raphaelchaib / main.js
Created June 28, 2016 04:50
Javascript: Read cookie value
function read_cookie(key){
var result;
return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? (result[1]) : null;
}
@raphaelchaib
raphaelchaib / 000_system.md
Last active May 30, 2020 15:41
Linux Essential Commands

PATH

  • System wide PATH configuration

Edit /etc/environment with:

PATH='/foo/bar:'$PATH
@raphaelchaib
raphaelchaib / merge.js
Last active August 29, 2016 21:27
Javascript: Merge two multidimensional objects, respecting it's type
function merge(A, B, depth) {
if ( typeof target !== 'object' ) {
target = {};
}
for (var property in source) {
if ( source.hasOwnProperty(property) ) {
var sourceProperty = source[ property ];
if ( typeof sourceProperty === 'object' ) {
target[ property ] = merge( target[ property ], sourceProperty );
@raphaelchaib
raphaelchaib / clone.js
Created June 8, 2016 17:30 — forked from joshcarr/clone.js
Javascript Cloning
// FROM http://stackoverflow.com/questions/728360/most-elegant-way-to-clone-a-javascript-object
// When I had to implement general deep copying I ended up compromising by
// assuming that I would only need to copy a plain Object, Array, Date, String,
// Number, or Boolean. The last 3 types are immutable, so I could perform a
// shallow copy and not worry about it changing. I further assumed that any
// elements contained in Object or Array would also be one of the 6 simple
// types in that list. This can be accomplished with code like the following:
function clone(obj) {
@raphaelchaib
raphaelchaib / clone_anythings.js
Created June 7, 2016 22:19 — forked from chrisyip/clone_anythings.js
Clone Anything with JavaScript
// http://davidwalsh.name/javascript-clone
function clone(src) {
function mixin(dest, source, copyFunc) {
var name, s, i, empty = {};
for(name in source){
// the (!(name in empty) || empty[name] !== s) condition avoids copying properties in "source"
// inherited from Object.prototype. For example, if dest has a custom toString() method,
// don't overwrite it with the toString() method that source inherited from Object.prototype
s = source[name];
if(!(name in dest) || (dest[name] !== s && (!(name in empty) || empty[name] !== s))){
@raphaelchaib
raphaelchaib / Keybinds.sublime-keymap
Last active August 28, 2016 20:31
Sublime Text 3 Configurations
[
{ "keys": ["ctrl+tab"], "command": "next_view" },
{ "keys": ["ctrl+shift+tab"], "command": "prev_view" },
{ "keys": ["ctrl+shift+s"], "command": "prompt_save_as" },
{ "keys": ["ctrl+shift+a"], "command": "expand_selection", "args": {"to": "tag"} },
]
@raphaelchaib
raphaelchaib / script.js
Last active March 1, 2016 04:41
JavaScript: Animate counter on document scroll
// statistics counter animation
var counterFx = function counterFx(element) {
var dfd = element.map(function(i, el) {
var data = parseInt(this.dataset.value.replace(/[\.,]+/g, ''));
var props = {
"from": {
"count": 0
},
"to": {
"count": data