Skip to content

Instantly share code, notes, and snippets.

View cantlin's full-sized avatar

Cantlin Ashrowan cantlin

View GitHub Profile
require "twitter"
require "curb"
require "pp"
require "json"
require "opengraph_parser"
puts "Authenticating..."
client = Twitter::REST::Client.new do |config|
config.consumer_key = "foo"
define(['angular', 'lodash'], function(angular, _) {
'use strict';
var mod = angular.module('guardianCardServices', []);
// Matches on any Guardian content URL
// Higher priority services (e.g. video embed) should be tried first
var guCardUriPattern = /https?:\/\/www\.theguardian\.com\/.*\/\d{4}\/.*/;
// var guCardEmbedApiHost = "http://embed.theguardian.com/oembed/"
require 'curb'
require 'json'
require 'sinatra'
last_poll = Time.now
poll_interval = 10
borked_videos = []
EXPECT_ENCODINGS = ['video/mp4','video/3gp:small','video/3gp:large','video/m3u8','video/webm']
Thread.abort_on_exception = true
#! /usr/bin/env ruby
require "json"
infile = "antarctica_hits"
lines = File.readlines infile
parsed_lines = lines.map do |line|
line = line.gsub(/2014-02-28T12-ip-10.*\.internal:/, "")
JSON.parse(line) rescue next
@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