Skip to content

Instantly share code, notes, and snippets.

eval(atob('0xF14e/0xF144/0xF141/0xF173/0xF14e/0xF144/0xF141/0xF173/0xF14e/0xF144/0xF145/0xF173/0xF14e/0xF16a/0xF145/0xF173/0xF14e/0xF16a/0xF149/0xF173/0xF14d/0xF17a/0xF16b/0xF173/0xF14d/0xF154/0xF141/0xF135/0xF14c/0xF144/0xF145/0xF177/0xF14d/0xF153/0xF177/0xF178/0xF14d/0xF144/0xF16b/0xF173/0xF14d/0xF154/0xF141/0xF178/0xF14c/0xF144/0xF145/0xF178/0xF14e/0xF153/0xF177/0xF17a/0xF14f/0xF153/0xF177/0xF130/0xF14d/0xF153/0xF177/0xF130/0xF14d/0xF143/0xF177/0xF130/0xF14d/0xF151/0xF13d/0xF13d'.split('/').map(l => l.split('0xF1')[1]).map(n => parseInt(n, 16)).map(n => String.fromCharCode(n)).join('')).split(',').map(n => String.fromCharCode(n)).join(''))
@whatAboutJohn
whatAboutJohn / utils.js
Last active February 8, 2019 12:25
Utility functions for JS
/**
Fetch nested properties, returns undefined instead of throwing error.
@example
const obj = { deep: { nested: stuff: 1 } }
dig(obj, 'deep.something.something.darkside') #=> undefined
*/
function dig (o, p, c = 0) {
const ps = p.split('.'), cr = ps[c]
return ps.length - 1 === c ? undefined : typeof o[cr] === 'object' && !o[cr] instanceof Array ? dig(o[cr], p, c + 1) : o[cr]
}
@whatAboutJohn
whatAboutJohn / survey.js
Last active April 7, 2017 21:45
Script to map questions to answers on surveys.
/**
* @author John Molina <jmolina@pixnabilab.com>
* Creates a Survey class that gathers data based on chosen answers and returns
* a key object that will be mapped against a dictionary of answers.
* @class
* @param {Object} answers
*/
class Survey extends EventEmitter {
constructor(answers) {
super()
@whatAboutJohn
whatAboutJohn / git_alias_dif
Created January 18, 2016 19:15
Adds "dif" alias to git to enable text search of an unstaged file.
# Add this line to ~/.gitconfig in [alias].
dif = "!sh -c \"git diff $(git diff --name-only -- \"*$1*\")\""
@whatAboutJohn
whatAboutJohn / canvas_mousemove_path.js
Created September 26, 2015 07:29
Capture the Path on mousemove.
'mouse:move': function(event) {
if (mouse_down_status) {
var grouped_path = [];
var points = canvas.freeDrawingBrush.convertPointsToSVGPath(canvas.freeDrawingBrush._points);
points = points.filter(function(n){ return n != ' ' });
points.map(function(e, i) {
if (typeof points[i] == 'string') {
points[i] = points[i].replace(/ /g,'');
}
});
include Math
require "bigdecimal/math"
include BigMath
# Sum all odd PI digits from 1 to 31415
PI(31415).to_digits.tr('.', '').split('').select.each_with_index {|s, i| i.even?}.tap {|x| p x.map(&:to_i).inject(0, &:+)}