Skip to content

Instantly share code, notes, and snippets.

View cantlin's full-sized avatar

Cantlin Ashrowan cantlin

View GitHub Profile
@cantlin
cantlin / hacked_bookmarklet
Created July 20, 2013 15:02
opens a guardian url in the api
javascript:var u='content.guardianapis.com';window.open((window.location.toString().split('#')[0].split('?')[0] + '.json?api-key=hackedio&show-fields=all&show-tags=all&show-media=all').replace('www.guardian.co.uk', u).replace('m.guardian.co.uk', u));
// Convert an HSBC "previous statement" page into a CSV
var year = 2013,
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
var output = '',
rows = $('table').last().find('tr');
rows.each(function(i, row) {
if(i === 1 || i === rows.length - 1) return;
#! /bin/bash
x=`identify -format "%w" $1`
y=`identify -format "%h" $1`
data=`openssl base64 < $1 | tr -d '\n'`
type=`file --mime-type -b $1`
echo "display:block;
font:0/0 a;
color:transparent;
# Make sure we have MIME types set up for WOFF, EOT and TT fonts.
# Existing mappings for these extensions are overridden.
AddType application/font-woff .woff # http://www.w3.org/TR/WOFF
AddType application/x-font-ttf .ttf # No standard type for TT
AddType application/vnd.ms-fontobject .eot # iana.org/assignments/media-types/application
# Ensure the JS MIME type is set to what we expect.
AddType application/javascript .js
class Dictionary
def initialize
@words = read_source
end
def include? word
self.words.include? word
end
#! /usr/bin/ruby
require 'dictionary'
require 'suggester'
dict = Dictionary.new
loop do
print '> '
word = gets
class Suggester
class << self
def variants_for word
[word.downcase, word.capitalize, word.squeeze]
end
def suggestions_for word
suggestions = self.vowel_suggestions_for word
suggestion_variants = []
def following(cursor = -1)
Rails.cache.fetch("following/#{id}", :expires_in => 1.hour) do
result = twitter_request_authenticated('get_following', {:cursor => cursor})
followed_users = parse_body(result)['users']
twitter_user_list = []
followed_users.each do |user|
# this_user = TwitterUser.new(:twitter_id => user['id'], :screen_name => user['screen_name'], :name => user['name'], :image => user['profile_image_url'], :location => user['location'])
this_user = {'twitter_id' => user['id'], 'screen_name' => user['screen_name'], 'name' => user['name'], 'image' => user['profile_image_url'], 'location' => user['location']}
this_user['status'] = user['status']['text'] unless user['status'].nil?
twitter_user_list.push this_user
# "Empty" results when this model method resides in a cache block
# app/models/user.rb
def following(cursor = -1)
Rails.cache.fetch("following/#{id}", :expires_in => 1.hour) do
result = twitter_request_authenticated('get_following', {:cursor => cursor})
followed_users = parse_body(result)['users']
twitter_user_list = []
followed_users.each do |user|
<div class="followed-user <%= cycle('odd odd-row', 'even odd-row', 'odd even-row', 'even even-row') %><% if(followed_user_counter > 20) %> hidden<% end %>">