Skip to content

Instantly share code, notes, and snippets.

View bradly's full-sized avatar

Bradly Feeley bradly

View GitHub Profile
@bradly
bradly / i18n.js
Created August 26, 2011 17:31
Simple JavaScript Unit Testing
// i18n.js
// Copyright 2011 Bradly Feeley
// Language attribute should be added to the html nodes.
// <html lang="en">
//
// Alternatively, you can set the language by passing an argument to the I18n.set_locale function.
//
// Early in the layout view before all other js:
// <script src="/javascripts/i18n.js" type="text/javascript" charset="utf-8"></script>
@bradly
bradly / gist:1525252
Created December 27, 2011 21:43
Ryan's For People Not Getting It
How I Explained REST to My Dad
Sunday, December 12, 2004
Translations of the following dialog available in Japanese, French, Vietnamese, Italian, Spanish, Portuguese, and Chinese. Huge thanks to YAMAMOTO Yohei, Karl Dubost, jishin, Barbz, Tordek, Edgard Arakaki, keven lw, respectively. If you know of additional translations, please leave a comment with the location.
Dad: Who is Roy Fielding?
Ryan: Some guy. He’s smart.
@bradly
bradly / 1st_chunk[py2k].py
Created August 26, 2012 21:53
Stripe CTF 2.0, level8, py2k webhook for getting the 1st chunk
from os import curdir, sep
import httplib
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
workvar = 0
# arrvar holds the remaining possible solutions to this block
arrvar = range(999)
globport = 0
# config vars:
serva8 = "level08-3.stripe-ctf.com" #level8 server
<?php
// TimThumb script created by Tim McDaniels and Darren Hoyt with tweaks by Ben Gillbanks
// http://code.google.com/p/timthumb/
// MIT License: http://www.opensource.org/licenses/mit-license.php
/* Parameters allowed: */
// w: width
@bradly
bradly / active_record_singleton.rb
Created April 26, 2013 17:28
A simple lib to make an active record class work with a single row. Not sure how I feel about it yet, but it really came in handy in a current app.
module ActiveRecordSingleton
def self.included(base)
base.class_eval do
class << self
delegate :attributes, :save, :save!, :update_attribute, :update_attributes, :update_attributes!, :update_column, to: 'instance'
[:new, :create, :create!, :destroy, :destroy_all, :delete, :delete_all].each do |method_name|
undef_method method_name
end
buffer = ''
cipher = nil
render :text => proc { |response, output|
s3.get(bucket, key_path) do |chunk|
# decrypt chunk
if buffer == ''
# first chunk
buffer << chunk
# extract the magic string and salt
magic_test = buffer.slice!(0..EncryptionHelper.magic_string.length-1)
e299a5efb88f2049276c6c20626520746865726520696e207468652066696e657374205475657364617920737765617465722120e299a5efb88f
@bradly
bradly / gist:bf0b55c0bd6faeac94f6
Created September 15, 2014 15:51
You don't trust me??
ruby -e 'puts `curl -s https://gist.githubusercontent.com/bradly/9b0536bd532718a0d22c/raw/d17a2106679a9f4034ba508ef388bf30b23ee54c/gistfile1.txt`.scan(/../).map { |c| c.hex.chr }.join'
package main
import "fmt"
import "os"
func main() {
source_dir_path := "/some/dir"
destination_dir_path := "/some/other/dir"
ensure_source_directory_exists(source_dir_path)
require 'uri'
class RootRelativeFilter < HTML::Pipeline::Filter
def call
doc.search("img").each do |img|
next if img['src'].nil?
src = img['src'].strip
if src.start_with? '/'
img["src"] = URI.join(context[:base_url], src).to_s