Skip to content

Instantly share code, notes, and snippets.

@hraban
hraban / vectorized-arrays.js
Last active Nov 10, 2016
Vectorized .all method on arrays to transparently access all members
View vectorized-arrays.js
Object.defineProperty(Array.prototype, 'all', {
get: function () {
return new Proxy(this, {
get: function(target, name, receiver) {
return target.map(x => x[name]);
},
set: function (target, name, value) {
target.forEach(x => x[name] = value);
},
// ... call:, etc.
@hc2p
hc2p / .travis.yml
Last active Dec 2, 2019
This is a prove of concept for leveraging the travis directory caching for speeding up docker builds. It works by configuring the docker deamon to use a folder under current user's (travis) control. That way you have the privileges to use the caching feature of travis ci.
View .travis.yml
sudo: false
services:
- docker
before_script:
- sudo service docker stop
- if [ "$(ls -A /home/travis/docker)" ]; then echo "/home/travis/docker already set"; else sudo mv /var/lib/docker /home/travis/docker; fi
- sudo bash -c "echo 'DOCKER_OPTS=\"-H tcp://127.0.0.1:2375 -H unix:///var/run/docker.sock -g /home/travis/docker\"' > /etc/default/docker"
- sudo service docker start
@bschlenk
bschlenk / ini2json.py
Last active Mar 3, 2017 — forked from Natim/ini2json.py
Convert an ini configuration file into a json file. Retains original order of ini file entries and prints json out with four space indentation.
View ini2json.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
import sys
from collections import OrderedDict
from ConfigParser import (ConfigParser, MissingSectionHeaderError,
ParsingError, DEFAULTSECT)
@Avaq
Avaq / combinators.js
Last active Jul 5, 2020
Common combinators in JavaScript
View combinators.js
const I = x => x;
const K = x => y => x;
const A = f => x => f(x);
const T = x => f => f(x);
const W = f => x => f(x)(x);
const C = f => y => x => f(x)(y);
const B = f => g => x => f(g(x));
const S = f => g => x => f(x)(g(x));
const P = f => g => x => y => f(g(x))(g(y));
const Y = f => (g => g(g))(g => f(x => g(g)(x)));
@andrew-d
andrew-d / main.c
Last active Dec 5, 2017
Example of how to get current binary's path using Apple's Code Signing Services
View main.c
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <Security/Security.h>
// Compile with:
// gcc -o ourpath -framework CoreFoundation -framework Security main.c
@hraban
hraban / pre-commit
Last active Apr 24, 2020
Prevent accidentally committing debug code in Git
View pre-commit
#!/bin/sh
# This pre-commit hook will prevent you from committing any line (or filename) containing
# the string NOCOMMIT. Use that tag in comments around source code you want to avoid
# accidentally committing, like temporary IP addresses or debug printfs.
#
# To add it to an existing repository, save it to .git/hooks/pre-commit (or append, if
# that file already exists). Remember to make executable (chmod +x ...)
#
# To automatically add this pre-commit hook to every repository you create or clone:
@Natim
Natim / ini2json.py
Created Jan 11, 2013
Convert an ini configuration file into a json file
View ini2json.py
# -*- coding: utf-8 -*-
import json
import sys
from ConfigParser import (ConfigParser, MissingSectionHeaderError,
ParsingError, DEFAULTSECT)
class StrictConfigParser(ConfigParser):
def _read(self, fp, fpname):
@hraban
hraban / gist:3017681
Last active Aug 15, 2016
My .emacs (hraban)
View gist:3017681
(add-to-list 'load-path "~/.emacs.d/plugins")
;; cl-* functions and macros
(require 'cl)
(cl-defmacro if-exists ((var fname) &rest body)
`(let ((,var ,fname))
(when (file-exists-p ,var)
,@body)))
@kerorotg
kerorotg / gist:1886569
Created Feb 22, 2012 — forked from ttilley/gist:1737625
mac sandbox and code signing conveniences
View gist:1886569
//
// CodeSignConveniences.h
//
// Created by Travis Tilley on 2/4/12.
// Copyright (c) 2012 Travis Tilley. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <Security/CodeSigning.h>
@keithamus
keithamus / Nano Git Commit Syntax highlighting
Created Dec 10, 2010
Add this to your ~/.nanorc and when running "git commit" (if your editor is nano) you'll have syntax highlighting in your commit message. Includes support for "git commit -v" too!
View Nano Git Commit Syntax highlighting
syntax "gitcommit" "COMMIT_EDITMSG$"
color white "#.*"
color green "#.(modified|deleted).*"
color yellow start="# Changes.*" end="# Changed.*"
color cyan start="# Untracked.*" end="diff"
color cyan start="# Untracked.*" end="$$"
color brightred "^deleted file mode .*"
color brightgreen "^\+.*"
color brightred "^-.*"
color brightyellow "^(diff|index|---|\+\+\+).*"
You can’t perform that action at this time.