Skip to content

Instantly share code, notes, and snippets.

View ThomasWunderlich's full-sized avatar

Thomas Wunderlich ThomasWunderlich

  • 17:26 (UTC -04:00)
View GitHub Profile
@chelmertz
chelmertz / pre-commit
Created February 8, 2011 09:25
pre-commit hook for git, running php lint
#!/usr/bin/php
<?php
// copied from http://phpadvent.org/2008/dont-commit-that-error-by-travis-swicegood
// authored by Travis Swicegood
$output = array();
$return = 0;
exec('git rev-parse --verify HEAD 2> /dev/null', $output, $return);
$against = $return == 0 ? 'HEAD' : '4b825dc642cb6eb9a060e54bf8d69288fbee4904';
@ndarville
ndarville / business-models.md
Last active January 13, 2024 17:27
Business models based on the compiled list at http://news.ycombinator.com/item?id=4924647. I find the link very hard to browse, so I made a simple version in Markdown instead.

Business Models

Advertising

Models Examples
Display ads Yahoo!
Search ads Google
@zoocoup
zoocoup / Casper Packaging & Deployment
Last active October 8, 2018 20:46
Overview of packaging for Casper
Casper Packaging & Deployment
# This document was made for my coworkers as I was leaving a previous job. The content should
# be applicable in most environments.
# Last Edit 20131008 - jkb | @zoocoup
This document is an overview of packaging applications, plug-ins and files or deployment with Casper.
_Testing the Application_
@ThomasWunderlich
ThomasWunderlich / whatserver.sh
Created June 6, 2014 04:08
Commands to identify most UNIX style OS' from Michael Henry @neocri.me
# Should work almost everywhere
uname -a ; grep -e . /etc/*_ver* /etc/*-rel* /etc/*-rel/* ; sw_vers
# Also relevant, but some systems don't have grep -R, -r, or --recursive
uname -a ; grep -Re . /etc/*_ver* /etc/*-rel* ; sw_vers
@abayer
abayer / jenkins-git-backup.sh
Last active July 16, 2024 17:17
Example of a script for backing up Jenkins config in git.
#!/bin/bash
#
# Copies certain kinds of known files and directories from a given Jenkins master directory
# into a git repo, removing any old ones, adds 'em, commits 'em, pushes 'em.
#
set -ex
if [ $# -ne 2 ]; then
echo usage: $0 root_dir jenkins_master
@steve-jansen
steve-jansen / README.md
Last active June 30, 2024 17:19
Stop and start Symantec Endpoint Protection on OS X

This script enables you stop and start Symantec Endpoint Protection on OS X

Installation

sudo curl https://gist.githubusercontent.com/steve-jansen/61a189b6ab961a517f68/raw/sep -o /usr/local/bin/sep
sudo chmod 755 /usr/local/bin/sep
sudo chown root:staff /usr/local/bin/sep
@afresh1
afresh1 / reprove.pl
Created November 24, 2014 23:30
A script that checks for changed files and re-runs prove if they have changed.
#!/usr/bin/perl
use strict;
use warnings;
use 5.010;
use File::Find;
my %options_that_take_arguments = map { $_ => 1 }
qw( I P M e exec harness formatter source a archive j jobs state rc );
@arobb
arobb / sierra-virtualbox-install.md
Last active November 24, 2020 13:15
Install macOS Sierra in VirtualBox on macOS host

Step 1 (Creating a bootable macOS Sierra ISO for VirtualBox):

  1. hdiutil attach /Applications/Install\ macOS\ Sierra\ Public\ Beta.app/Contents/SharedSupport/InstallESD.dmg -noverify -nobrowse -mountpoint /Volumes/install_app
  2. hdiutil create -o /tmp/Sierra.cdr -size 7316m -layout SPUD -fs HFS+J
  3. hdiutil attach /tmp/Sierra.cdr.dmg -noverify -nobrowse -mountpoint /Volumes/install_build
  4. asr restore -source /Volumes/install_app/BaseSystem.dmg -target /Volumes/install_build -noprompt -noverify -erase
  5. rm /Volumes/OS\ X\ Base\ System/System/Installation/Packages
  6. cp -rp /Volumes/install_app/Packages /Volumes/OS\ X\ Base\ System/System/Installation/
  7. cp -rp /Volumes/install_app/BaseSystem.chunklist /Volumes/OS\ X\ Base\ System/BaseSystem.chunklist

Scaling your API with rate limiters

The following are examples of the four types rate limiters discussed in the accompanying blog post. In the examples below I've used pseudocode-like Ruby, so if you're unfamiliar with Ruby you should be able to easily translate this approach to other languages. Complete examples in Ruby are also provided later in this gist.

In most cases you'll want all these examples to be classes, but I've used simple functions here to keep the code samples brief.

Request rate limiter

This uses a basic token bucket algorithm and relies on the fact that Redis scripts execute atomically. No other operations can run between fetching the count and writing the new count.

@bgribble
bgribble / git-chunks.py
Last active December 12, 2017 18:48
Split a source file into chunks, preserving git history
#! /usr/bin/env python3
'''
git-chunks - split a source file into multiple chunks, preserving Git
history of the source text
You have a too-big file foo.py that is old and crufty. In
your editor split it into multiple files foo-bar.py,
foo-baz.py, and foo-quux.py, with some desiccated remains
in foo.py still. So from Git's perspective you have unstaged