Skip to content

Instantly share code, notes, and snippets.

View henrygarner's full-sized avatar

Henry Garner henrygarner

View GitHub Profile
require 'spreadsheet'
# Code to add integer keys and Excel colorindex codes to
# ruby-spreadsheet's Font and Format api.
# eg. Spreadsheet::Format.new :color => 1
module Spreadsheet::Excel::Internals
(1..56).collect { |i| SEDOC_ROLOC[i.to_s.to_sym] = i + 7 }
end
@henrygarner
henrygarner / llr.rb
Created February 1, 2011 12:04
A simple Ruby demonstration of Ted Dunning's log-likelihood statistical measure, via Paul Rayson http://ucrel.lancs.ac.uk/llwizard.html
require 'matrix'
module LLR
def self.calculate(m)
2 * (m.to_a.flatten.h - m.row_vectors.map(&:sum).h - m.column_vectors.map(&:sum).h)
end
def sum
to_a.inject(nil) { |sum, x| x = yield(x) if block_given?; sum ? sum + x : x }
end
@henrygarner
henrygarner / tfidf.rb
Created February 2, 2011 11:34
TFIDF measure in ruby based on the DefaultSimilarity implementation in Apache Lucene, http://lucene.apache.org/
def similarity(term_frequency, document_frequency, documents_count)
idf = Math.log(documents_count / (document_frequency + 1.0)) + 1
Math.sqrt(term_frequency) * idf
end
@henrygarner
henrygarner / coleman_liau_string_ext.rb
Created March 9, 2011 22:48
Ruby Coleman-Liau string extension
# Code to calculate the Coleman-Liau index, which measures the understandability of a text.
# See http://en.wikipedia.org/wiki/Coleman-Liau_Index for more information
class String
def words
self.split(/[\W]? /)
end
def letters
self.scan(/\w/)
@henrygarner
henrygarner / gist:1035477
Created June 20, 2011 11:39
Likely Ltd Job Vacancy

About Likely Ltd

Likely Ltd are a funded startup specialising in highly targeting online publishing. We understand consumers’ interests, intent and behaviour online and use social platforms to talk to them about things that we know they will love. We manage hundreds of online accounts across multiple social media networks (each based around an interest, geographic location and consumer demographic), and we are scaling fast.

The company was founded at the beginning of this year by the team behind the @LDN twitter account. Our business is built on high-quality advertising, matching content to prospect so well that our audience enjoy even our sponsored messages. We already count several large global brands as clients, and are building out our communities beyond London to Europe and the US.

About the Vacancy

To efficiently grow our business, we are looking for rubyists who are motivated by the challenges presented by big data storage, analysis and navigation. We have a diverse database ecosystem inclu

// ==========================================================================
// Project: Sample
// Copyright: @2011 My Company, Inc.
// ==========================================================================
/*globals Sample */
Sample = SC.Application.create({
store: SC.Store.create().from(SC.Record.fixtures)
});
@henrygarner
henrygarner / gist:1123179
Created August 3, 2011 17:14 — forked from timcowlishaw/gist:1123148
Resources for setting up RVM and Passenger on Chef
http://www.agileweboperations.com/chef-rvm-ruby-enterprise-edition-as-default-ruby
http://www.christophersamuelson.com/2010/10/22/chef-rvm-capistrano-bundler/
http://blog.ninjahideout.com/posts/a-guide-to-a-nginx-passenger-and-rvm-server
http://brandontilley.com/2011/01/29/serving-rails-apps-with-rvm-nginx-unicorn-and-upstart.html
http://brandontilley.com/2011/01/29/rvm-unicorn-and-upstart.html
Chef workflow
# Install cookbook from opscode community site. (Automatically commits to local repo)
knife cookbook site install <COOKBOOK_NAME>

We're Likely Ltd

We're the company behind many Facebook and Twitter accounts, such as Handpicked London on Facebook or @LDN on Twitter. We're a funded startup, and we try to find the best of the web around a particular topic to present to our communities. To do this efficiently with our small team (there's six of us, and just two technical staff) we are working on some challenging NLP, machine learning and 'big data' problems. In addition to content discovery, we have also built tools for online marketing. We use these tools ourselves but also apply their smarts on clients' behalf.

What we're after

To improve our public and client facing web presence we're looking to bring on a full time, full stack web developer to work on several self-contained and mostly green field projects.

The projects are diverse, and range from traditional click-to-buy customer facing web apps, to the specification of **

Ducklink::Decorator.configure do
group do
template 'http://affiliate.example.com?clickref={{reference}}&url={{url}}#campaign={{campaign}}'
host 'buy.example.com', 'shop.example.com' do |context|
set :campaign, 'campaign1'
set :reference, context[:reference]
end
host 'another.com' do |context|
set :campaign, 'campaign2'
set :reference, context[:reference]
;; https://4clojure.com/problem/26
(partial (fn f [a b n]
(if (= n 0) ()
(cons a (f b (+ a b) (- n 1)))
)
) 1 1)