Skip to content

Instantly share code, notes, and snippets.

View christophemarois's full-sized avatar

Christophe Marois christophemarois

  • Pathway Medical
  • Montreal
View GitHub Profile
@christophemarois
christophemarois / urlInfo.js
Last active January 8, 2016 20:30
Get url info in the DOM
function urlInfo (url) {
var props = 'hash host hostname href origin password pathname port protocol username search';
if (!window.urlInfoAnchorElement)
window.urlInfoAnchorElement = document.createElement('a');
urlInfoAnchorElement.href = url;
return props.split(' ').reduce(function (m, v, i) {
@christophemarois
christophemarois / multilineStr.js
Created January 13, 2016 04:15
pre-ES6 multiline strings
m = function (func) {
return func.toString()
.replace(/^[^{]+{\s*\/\*\s*/m, "")
.replace(/\s*\*\/\s*}$/m, "");
};
var str = m(function(){/*
everything in here
is a multiline string
it is a secret.
@christophemarois
christophemarois / hybrid-singletons.js
Created January 15, 2016 18:10
Removes the need for 'new' to instantiate a singleton in javascript
/* Hybrid singletons. removes the need for 'new' */
/* Really more an experiment than anything */
function Person (name, age) {
var parentFn = this[arguments.callee.name];
if (parentFn && !(this instanceof parentFn))
return new (Function.prototype.bind.apply(
parentFn, [this].concat(Array.from(arguments))));
@christophemarois
christophemarois / throttle.js
Created January 15, 2016 22:42
Simplest throttle function possible
function throttle (fn, limit) {
var wait = false;
return function () {
if (wait) return;
fn.call(); wait = true;
setTimeout(function () { wait = false; }, limit);
}
};
@christophemarois
christophemarois / crazytext.js
Created January 17, 2016 06:11
Make text lose it on hover
$(function(){
var speed = 80, times = 3;
$(document).on('mouseover', '[data-shuffle]', function (e) {
var $this = $(this);
if (!$this.data('text'))
$this.data('text', $this.text());
@christophemarois
christophemarois / jumpytext.js
Created January 21, 2016 15:18
links that can't hold their shit together
$(function(){
var speed = 80, times = 3;
$(document).on('mouseover', '[data-shuffle]', function (e) {
var $this = $(this);
if (!$this.data('text'))
$this.data('text', $this.text());
@christophemarois
christophemarois / instagram-scraper.rb
Created January 20, 2016 17:22
Downloader for the instagram-screen-scrape command-line utility
#!/usr/bin/env ruby
require 'json'
photos = JSON.parse(`instagram-screen-scrape -u #{ARGV[0]}`).each { |p|
system("curl -LO #{p['image']}")
}
@christophemarois
christophemarois / enumeration.js
Created February 4, 2016 01:45
Join enumerations by commas and “and”
arr = [1, 2, 3, 4]
arr.slice(0, -2).concat([arr.slice(-2).join(' and ')]).join(', ')
// => '1, 2, 3 and 4'
@christophemarois
christophemarois / watch_folder.sh
Created February 22, 2016 22:09
Pure bash folder watching
#!/bin/bash
SRC=./src
SECONDS=1
on_change () {
# $1, $2, $3... etc. are the files created/modified
}
@christophemarois
christophemarois / mkdirpSync.js
Created February 24, 2016 18:02
Synchronously make directories from multiple paths at once while failing silently if path exists
module.exports = function mkdirpSync () {
var fs = require('fs')
, path = require('path');
var dirPaths = Array.from(arguments);
dirPaths.forEach(function (dirPath) {
var parts = dirPath.split(path.sep);
for( var i = 1; i <= parts.length; i++ ) {