Skip to content

Instantly share code, notes, and snippets.

@olih
olih / jq-cheetsheet.md
Last active April 17, 2024 19:46
jq Cheet Sheet

Processing JSON using jq

jq is useful to slice, filter, map and transform structured json data.

Installing jq

On Mac OS

brew install jq

@ryanflorence
ryanflorence / angular.js
Last active October 30, 2019 01:42
Comparing an avatar implementation with angular and ember. http://www.angularails.com/articles/creating_simple_directive_in_angular
// Because people can't seem to find the gist description, here is the source
// of this code, a post found in last weeks JS Weekly, it is not my code
// http://www.angularails.com/articles/creating_simple_directive_in_angular
angular.module('ui-multi-gravatar', [])
.directive('multiAvatar', ['md5', function (md5) {
return {
restrict: 'E',
link:function(scope, element, attrs) {
@polotek
polotek / .gitignore
Last active October 5, 2015 13:57
A little wrapper around localStorage that supports compound keys and non-string values
# Logs
logs
*.log
# Runtime data
pids
*.pid
*.seed
# Directory for instrumented libs generated by jscoverage/JSCover
@unclebob
unclebob / apology.
Created April 27, 2012 12:19
Apology to Women Programmers.
Today I gave a keynote at ACCU in Oxford. In the midst of it I made two (count them) two statements that I should have known better than to make. I was describing the late '70s, and the way we felt about the C language at the time. My slide said something like: "C was for real men." Emily Bache, whom I know and hold in high regard, spoke up and said "What about women?". And I said something like: "We didn't allow women in those days." It was a dumb crack, and should either not have been said, or should have been followed up with a statement to the effect that that was wrong headed.
The second mistake I made was while describing Cobol. I mentioned Adm. Grace Hopper. I said something like "May she rest in peace." I don't know that any of the words were actually demeaning, but the tone was not as respectful as it should have been to an Admiral in the United State Navy, and one who was so instrumental in our industry; despite what I feel about Cobol.
I am a 59 year old programmer who was brought up
@mikeal
mikeal / gist:2504336
Created April 27, 2012 00:11
Date parsing JSON
JSON._dateReviver = function (k,v) {
if (v.length !== 24 || typeof v !== 'string') return v
try {return new Date(v)}
catch(e) {return v}
}
JSON.parseWithDates = function (obj) {
return JSON.parse(obj, JSON._dateReviver);
}
@polotek
polotek / HTTPClient.js
Created April 22, 2012 03:37
A node http client that adds things like retry behavior
var request = require('request')
, retry = require('retry')
, httpLog = log4js.getLogger('httpLog');
var HTTPClient = {
defaultOpts: {
, request: {
headers: {
Host: 'paddie'
, 'Content-Type': 'application/javascript'
@steckel
steckel / hi-res-web.md
Created March 2, 2012 19:58
Hi-Res Web

Hi-res web

What the hell is going on here?

This is already happening. We have devices in the market that already have high pixel density displays besides Apple's Retina screens and we know no one plans on scaling back on this technology. We also know that, all though, the majority of these devices are on mobile phones and tablets, mobile is playing a larger part in the web and also isn't going to start slowing down any time soon.

Will we all just blindly follow Apple's iOS workflow and create multiple assets for multiple resolution targets? some-image.png and some-image@2x.png?

There's definitely more options than this and the web isn't such a simple place where we can just accept apple's native app work flow and expect it to work without any consequences.

@polotek
polotek / from_benchmark.js
Created January 24, 2012 01:36
Deep object clone
// From benchmark.js - https://github.com/bestiejs/benchmark.js/blob/33aca33e4986386d782bbc7c2ab85cf34ed90bd2/benchmark.js
/**
* A deep clone utility.
* @static
* @memberOf Benchmark
* @param {Mixed} value The value to clone.
* @returns {Mixed} The cloned value.
*/
function deepClone(value) {
var accessor,
@dherman
dherman / loop-controls.js
Created January 13, 2012 22:50
using loop controls from within block lambdas
Mailbox.prototype.extractContents = function(contacts) {
let messages = this.messages;
loop:
for (let i = 0, n = messages.length; i < n; i++) {
messages[i].headers.forEach { |header|
if (header.isSpam())
continue loop; // the label is not strictly necessary here
let addresses = header.extractAddresses();
addresses.forEach { |addr|
var fs = require('fs')
var DataCollector = function(arr) {
this.setFiles(arr)
}
DataCollector.prototype = {
setFiles: function(arr) {
this.files = arr
}