Instantly share code, notes, and snippets.

View batch.py
from itertools import islice, chain
def batch(iterable, size):
iterator = iter(iterable)
for first in iterator:
yield chain([first], islice(iterator, size - 1))
View npm.sh
npm () {
[ -n "$NODE_VERSION" ] || NODE_VERSION="latest"
tty=
tty -s && tty=--tty
docker run \
$tty \
--interactive \
--rm \
--user $(id -u):$(id -g) \
View mphp
#!/usr/bin/env bash
#
# Copyright (c) 2016 Matthew Loberg
# Distributed under the MIT License (http://opensource.org/licenses/MIT)
#
# ==========================
# Manage PHP (uses Homebrew)
# ==========================
#
# Commands:
View comparison.php
<?php
function compareHashes($hashOne, $hashTwo)
{
$result = 0;
for ($i = 0; $i < strlen($hashOne); $i++) {
$charOne = substr($hashOne, $i, 1);
$charTwo = substr($hashTwo, $i, 1);
$intOne = base_convert($charOne, 16, 10);
View FormCollectionView.js
/**
* @fileOverview Form collection handler
*
* @author Matthew Loberg
*/
define(function(require, module, exports) {
'use strict';
var $ = require('jquery');
View nginx.conf.erb
<%# modules/common/templates/nginx.conf.erb %>
# Example template for PHP-FPM based projects
#
# The template which nginx uses within a boxen::project can be overridden
# to a specific template such as this one.
#
# You will likely need to change both the root and SCRIPT_FILENAME parameters below
# to match your setup
#
server {
View flickr.php
<?php
$id = '30065870@N08'; // Find your Flickr ID at http://idgettr.com
$url = 'http://api.flickr.com/services/feeds/photos_public.gne?id='.$id.'&format=json';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($ch);
curl_close($ch);
// Remove jsonp callback (jsonFlickrFeed) and escaped characters (except ")
View FreshCutDark.tmTheme
<!--
======================================================================
FreshCut Dark - Based on FreshCut by Dayle Rees
======================================================================
A Sublime Text 2 / Textmate theme.
Copyright (c) 2012 Dayle Rees.
Released under the MIT License <http://opensource.org/licenses/MIT>
----------------------------------------------------------------------
Find more themes at : https://github.com/daylerees/colour-schemes
----------------------------------------------------------------------
View Guardfile
require 'jekyll'
module ::Guard
class Jekyll < Guard
def start
puts "Starting Jekyll on port #{port}"
options = ::Jekyll.configuration({:serving => true, :watch => true, :port => port})
p = ::Process.fork do
::Jekyll::Commands::Build.process(options)
::Jekyll::Commands::Serve.process(options)
View lock.py
import sys
import fcntl
LOCK_EX = fcntl.LOCK_EX
LOCK_SH = fcntl.LOCK_SH
LOCK_NB = fcntl.LOCK_NB
class Flock(object):