Skip to content

Instantly share code, notes, and snippets.

View lusis's full-sized avatar

John E. Vincent lusis

View GitHub Profile
@mamantoha
mamantoha / common_prefix.rb
Created October 16, 2012 11:04
Finding the longest common prefix of an array of paths in Ruby
# Return the longest path prefix (taken character-by-character) that is a prefix of all paths in array.
# If array is empty, return the empty string ('').
# Note that this may return invalid paths because it works a character at a time.
#
def common_prefix(m)
# Given a array of pathnames, returns the longest common leading component
return '' if m.empty?
s1, s2 = m.min, m.max
s1.each_char.with_index do |c, i|
return s1[0...i] if c != s2[i]
@juanje
juanje / gist:3797297
Created September 28, 2012 00:38
Mount apt cache of a Vagrant box in the host to spin up the packages installation

This is a little trick I use to spin up the packages instalation on Debian/Ubuntu boxes in Vagrant.

I add a simple function that checks if a directory named something similar to ~/.vagrant.d/cache/apt/opscode-ubuntu-12.04/partial (it may have another path in Windows or MacOS) and create the directory if it doesn't already exist.

def local_cache(basebox_name)
  cache_dir = Vagrant::Environment.new.home_path.join('cache', 'apt', basebox_name)
  partial_dir = cache_dir.join('partial')
  partial_dir.mkdir unless partial_dir.exist?
 cache_dir
@jordansissel
jordansissel / RESULTS.md
Created September 21, 2012 07:41
screenshot + code showing how to query logstash/elasticsearch with a graphite function.

logstash queries graphed with graphite.

Operation: Decouple whisper from graphite.

Method: Create a graphite function that does a date histogram facet query against elasticsearch for a given query string for the time period viewed in the current graph.

Reason: graphite has some awesome math functions. Wouldn't it be cool if we could use those on logstash results?

The screenshot below is using logstash to watch the twitter stream of keywords "iphone" "apple" and "samsung" - then I graph them each, so we get an idea of popularity. As a bonus, I also do a movingAverage() on the iphone curve to show you why this is awesome.

@daurnimator
daurnimator / app.lua
Created September 14, 2012 10:11
Sinatra like clone for lua
if not sinatra.incoming ( ngx.req.get_method() , ngx.var.uri ) then
return ngx.exit ( 404 )
end
@bryanhunter
bryanhunter / about.txt
Created August 8, 2012 17:20
Testing idea of using sum of card numbers as security question
Based on Twitter conversation with @b6n
*Question 1*
The digits in the credit card pattern 4811 XXXX XXXX 2632 sum to 77, what are the
middle 8?There are 112,400 card numbers (about 1.2%) in this range that 1) pass
the luhn check and 2) sum to 77. The credit card isn't in great danger.
*Question 2*Does the sum of the card digits make a good security question for
phone support?The first hurdle is having a customer add the 16 digits without
miss-adding or freaking out. Next, the numbers do cluster to the middle. A bad
@postmodern
postmodern / Makefile
Last active March 4, 2024 14:42
A generic Makefile for building/signing/install bash scripts
NAME=project
VERSION=0.0.1
DIRS=etc lib bin sbin share
INSTALL_DIRS=`find $(DIRS) -type d 2>/dev/null`
INSTALL_FILES=`find $(DIRS) -type f 2>/dev/null`
DOC_FILES=*.md *.txt
PKG_DIR=pkg
PKG_NAME=$(NAME)-$(VERSION)
web: gunicorn -w4 -b0.0.0.0:$PORT app:app
@tobyhede
tobyhede / postsql.sql
Created May 17, 2012 03:08
PostgreSQL as JSON Document Store
-- PostgreSQL 9.2 beta (for the new JSON datatype)
-- You can actually use an earlier version and a TEXT type too
-- PL/V8 http://code.google.com/p/plv8js/wiki/PLV8
-- Inspired by
-- http://people.planetpostgresql.org/andrew/index.php?/archives/249-Using-PLV8-to-index-JSON.html
-- http://ssql-pgaustin.herokuapp.com/#1
-- JSON Types need to be mapped into corresponding PG types
--
@jtimberman
jtimberman / tmux.conf
Created April 24, 2012 02:26
solarize-ified colors a bit more, looks decent in light and dark (iterm2)
# bindings
unbind C-a
set -g prefix C-z
bind C-z send-prefix
unbind [
unbind %
unbind '"'
bind Escape copy-mode
@apk
apk / websock.sh
Created April 18, 2012 15:51
A web socket server as a bash script.
#!/bin/bash
# WebSocket shell, start & browse to http://<Host>:6655/
# Requires bash 4.x, openssl.
# Author: [email protected] (which isn't me, apk)
coproc d { nc -l -p 6656 -q 0; }
nc -l -p 6655 -q 1 > /dev/null <<-ENDOFPAGE
HTTP/1.1 200 OK
<html><head><script language="javascript">
var url = location.hostname + ':' + (parseInt(location.port) + 1);