Skip to content

Instantly share code, notes, and snippets.

/*
* A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
* in FIPS 180-1
* Version 2.2-alpha Copyright Paul Johnston 2000 - 2002.
* Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
* Distributed under the BSD License
* See http://pajhome.org.uk/crypt/md5 for details.
*/
/*
@schacon
schacon / gist:793c8fdea738fd3d04a7
Created December 18, 2014 16:25
crush and resize book images
#! /usr/bin/env ruby
require 'rubygems'
require 'oily_png'
Dir.glob("book/**/*.png").each do |file|
puts file
image = ChunkyPNG::Image.from_file(file)
p image.width
p image.height
if image.width > 800 || image.height > 800
@schacon
schacon / cohort.sql
Last active November 3, 2020 23:38
Cohort Month Base Values for BigQuery
select month, months_out from (
select month,
GENERATE_ARRAY(0, DATE_DIFF(CURRENT_DATE(), month, MONTH)) as months,
from UNNEST(
(select
GENERATE_DATE_ARRAY(CAST([STARTING_DATE] AS DATE), CAST(max(date_field) AS DATE),
INTERVAL 1 MONTH) as date
from [SOME_TABLE_WITH_A_DATE_FIELD])
) as month
) CROSS JOIN UNNEST(months) as months_out
@schacon
schacon / gistie.rb
Created July 22, 2008 14:17 — forked from anonymous/gistie
create a gist on the command line
#!/usr/bin/env ruby
require "tempfile"
GIST_URL = 'http://gist.github.com/gists'
if ARGV.include? "-p"
text = `pbpaste`
elsif !ARGV.empty?
@filename = ARGV.shift
text = File.read(File.expand_path(@filename))
@schacon
schacon / gist:20
Created July 20, 2008 19:17 — forked from mojombo/wtf.rb
.,mlkmlkml
Git is an open source, distributed version control system implemented
as a directed acyclic graph of commit objects pointing to snapshots
of content, with all data saved in it's own custom content addressable
filesystem by the SHA-1 checksum hash of each objects data. branches
are simply pointers into this directed graph of commits, identifying
entry points that designate the latest work on that branch, allowing
Git to traverse the pointers, determining a coherent history.
this makes branching cheap and easy, and merging simple, encouraging
non-linear development styles and frictionless context switching while
facilitating distributed development, cryptographic integrity and late
@schacon
schacon / example_gist_create.rb
Created August 6, 2008 20:29
gist example api post
require 'net/http'
require 'uri'
# /api/v1/:format/new
# /api/v1/:format/gists/:user
# /api/v1/:format/:gist_id
res = Net::HTTP.post_form(URI.parse('http://gist.github.com/api/v1/xml/new'),
{ 'files[file1.ab]' => 'CONTNETS',
'files[file2.ab]' => 'contents' })
@schacon
schacon / stopwatch.rb
Created June 22, 2011 15:59
simple ruby stopwatch
class Stopwatch
attr_writer :splits, :max, :start, :end, :total
def initialize(message)
@message = message
@splits = []
@max = 5
end
/tmp/compare/svn$ svn commit -m 'commit me'
Sending what.txt
Transmitting file data .
Committed revision 13.
/tmp/compare/svn$ svn info
Path: .
URL: http://localhost:5203/svn
Repository Root: http://localhost:5203/svn
Repository UUID: 3b9a9e50-8ead-4325-b308-a6ad9b1ac2aa
#! /usr/bin/env ruby
# this script takes your current commit, finds all the submodules in it,
# makes them static files in a new tree and updates a branch called 'heroku'
# - this way you can push a project with submodules to heroku easily
# just run this, then run "git push heroku heroku:master"
current_commit = `git rev-parse HEAD`
current_tree = `git rev-parse HEAD^{tree}`
puts "Starting at tree #{current_tree}"