Skip to content

Instantly share code, notes, and snippets.

@mattijs
mattijs / README.md
Last active June 8, 2020 15:59
strftime for JavaScript Dates

strftime

Selective implementation of strftime

This is an implementation of Unix strftime for JavaScript Dates supporting only American English (en_US). Not all format options are implemented.

I only had use cases for formatting in American English (en_US) for this function and most conversion characters are also implemented based on use cases I had.

It would be possible to adapt this to support a different language or multiple languages but I have no use cases for this. Feel free to use this code any way you like. I just copy this into projects and adapt it to the project specific needs, this is just a capture of the code at a certain point in time.

@mattijs
mattijs / curry.js
Created February 1, 2020 21:39
Currying Module
/**
* Curry the given function.
*
* @param {Function} fn
* @param {[...*]} initialArgs
* @returns {Function|*}
*/
export function curry(fn, ...initialArgs) {
return curryN(fn.length, fn, ...initialArgs);
}
@mattijs
mattijs / dombo.js
Last active October 31, 2018 02:32
DOM functions
// --- Selectors ---------------------------------------------------------
export function find(selector, el = document) {
return el.querySelector(selector);
}
export function findAll(selector, el = document) {
return el.querySelectorAll(selector);
}
@mattijs
mattijs / curry.js
Last active January 3, 2018 11:54
Curry function (JavaScript)
// Adaptation of http://chriswarbo.net/blog/2012-10-01-better_currying_in_javascript.html
/**
* Make the inout function f curryable.
*
* @param {function} f
* @returns {function}
*/
const curry = c = function(f) {
const apply = function(args) {
@mattijs
mattijs / keybase.md
Created November 30, 2016 03:29
keybase.md

Keybase proof

I hereby claim:

  • I am mattijs on github.
  • I am mattijs (https://keybase.io/mattijs) on keybase.
  • I have a public key whose fingerprint is C630 852B B446 9A5B 70DF 2D08 B9E5 2C7E 3E32 0693

To claim this, I am signing this object:

@mattijs
mattijs / dictstorage.py
Created December 7, 2012 11:45
Class for storing Google Credentials inside an existing dict
import threading
from oauth2client.client import Storage as BaseStorage
from oauth2client.client import Credentials
from oauth2client.anyjson import simplejson
def from_dict(container):
"""
Create a Credentials object from a dictionary.
@mattijs
mattijs / badwolf.less
Created October 24, 2012 18:05
badwolf colors for pygments
/* Color codes */
@plain: #f8f6f2;
@dalespale: #fade3e;
@snow: #ffffff;
@dirtyblond: #f4cf86;
@coal: #000000;
@taffy: #ff2c4b;
@brightgravel: #d9cec3;
@saltwatertaffy: #8cffba;
@lightgravel: #998f84;
@mattijs
mattijs / badwolf.itermcolors
Created October 24, 2012 18:02
badwolf iTerm2 colors
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Ansi 0 Color</key>
<dict>
<key>Blue Component</key>
<real>0.07884746789932251</real>
<key>Green Component</key>
<real>0.081504985690116882</real>
@mattijs
mattijs / test.js
Created August 14, 2012 19:12
Node Object comparison bug
// Values we check against
var obj = {};
var str = 'foo';
// Two identical functions
var isObjectA = function(o) {
return o === Object(o);
};
var isObjectB = function(o) {
return o === Object(o);
@mattijs
mattijs / test1.js
Created August 11, 2012 18:23
Backbone + Underscore + Request setups
/**
* Faulty test setup.
*
* Underscore recognizes the `foo_string` as an Object and
* the Backbone Model refuses to set the model value in the
* last case.
*/
var _ = require('underscore');
var Backbone = require('backbone');