This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
coerce-endtags: no | |
gnu-emacs: yes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//replace jquery/jquery with the repo you're interested in | |
fetch('https://api.github.com/repos/jquery/jquery/stats/contributors') | |
.then(response => response.json()) | |
.then(contributors => contributors | |
.map(contributor => contributor.weeks | |
.reduce((lineCount, week) => lineCount + week.a - week.d, 0))) | |
.then(lineCounts => lineCounts.reduce((lineTotal, lineCount) => lineTotal + lineCount)) | |
.then(lines => window.alert(lines)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function policyAllows(policies = [], item) { | |
for (var i = 0; i < policies.length; i++) { | |
if (!policies[i](item)) { | |
return false; | |
} | |
} | |
return true; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Class hack to get a reliable type description in JS | |
var type = v => ({}).toString.call(v).slice(8,-1) | |
// is a value a given native JS type (ignores inheritance etc) | |
var is = t => v => type(v) == t | |
// use the result of the 2nd function if the 1st fails | |
var either = (f1,f2) => v => f1(v) || f2(v) | |
// detect if a value is a POJO or an array |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create our server | |
var server; | |
server = http.createServer(function(req,res){ | |
// Set CORS headers | |
res.setHeader('Access-Control-Allow-Origin', '*'); | |
res.setHeader('Access-Control-Request-Method', '*'); | |
res.setHeader('Access-Control-Allow-Methods', 'OPTIONS, GET'); | |
res.setHeader('Access-Control-Allow-Headers', '*'); | |
if ( req.method === 'OPTIONS' ) { | |
res.writeHead(200); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// split and combine each array item | |
var combinePath = function(path, cb) { | |
return path.reduce(function(pre, cur){ | |
return pre.split(',').map(function(p) { | |
return !p ? cur : cur.split(',').map(function(v){ | |
return cb(p, v) | |
}).join(',') | |
}).join(',') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*.log | |
# vim files | |
*.swp | |
# emacs files | |
\#* | |
.#* | |
.~* | |
~* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// map key/value into newValue, each array elem holds: [key, value, newValue] | |
function cssobj_plugin_map (option) { | |
option = option || {} | |
var replaceMap = option.maps || [ | |
[ | |
'display', | |
'flex', | |
[ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// cssobj intro flexbox | |
function displayFlex() { | |
return { | |
display: [ | |
'-webkit-box', | |
'-webkit-flex', | |
'-moz-box', | |
'-ms-flexbox', | |
'flex' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Grateful thanks are given to Brian Marick (@marick) for helping me | |
;; write these. I got the original idea while reading through | |
;; http://xahlee.org/emacs/elisp_idioms.html, but couldn't work out | |
;; the elisp regexes. Brian Marick (@marick) stepped in and helped. He | |
;; took my tortured and broken camelcase-region and turned it into | |
;; something that actually worked. I then created | |
;; camelcase-word-or-region. I then wrote the snakecase versions but I | |
;; see now that all I did was copy the camelcase defuns over and, | |
;; meaning to go back and finish them Real Soon Now, forgot all about | |
;; them. I've had a quick look (2011-02-27) but elisp regexes are |