Skip to content

Instantly share code, notes, and snippets.

View thephw's full-sized avatar
❤️
Building software with love

Patrick Howard Wiseman thephw

❤️
Building software with love
View GitHub Profile
@thephw
thephw / multiplicative_pair_count.rb
Last active August 29, 2015 14:20
Count the number of pairs (x, y) such that x * y >= x + y
def multiplicative_pair_count(a,b)
count = 0
a.each_index.to_a.combination(2).each do |i,j|
c1 = a[i] + b[i]/1_000_000.0
c2 = a[j] + b[j]/1_000_000.0
count +=1 if c1*c2 >= c1+c2
return 1_000_000_000 if count >= 1_000_000_000
end
count
end
@thephw
thephw / min_abs_slice_sum.rb
Created April 29, 2015 21:06
Minimum absolute slice sum
def min_abs_slice_sum(a)
a.each_index.to_a.combination(2).map{|i,j| a[(i..j)].inject(&:+).abs}.min
end
def run_benchmark
require 'benchmark'
n = 3
Benchmark.bm(17) do |x|
(0..n).each do |i|
@thephw
thephw / get_length.rb
Created April 29, 2015 21:16
Get length of linked list
class IntList
attr_accessor :value, :next
end
def get_length(l)
return 0 if l.nil?
len = 1 + get_length(l.next)
end
ul{
list-style-type:none;
counter-reset: section;
}
li:before {
counter-increment: section;
content: counter(section);
}
li:nth-child(3n):before, li:nth-child(5n):before{
content: "";
@thephw
thephw / crontab
Last active August 29, 2015 14:24
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
require 'octokit'
ACCESS_TOKEN = "" # Create at https://github.com/settings/tokens
ORGANIZATION_NAME = "SalesLoft"
USER_NAME = "thephw"
PULL_REQUEST_OPTIONS = {state: :all, head: USER_NAME, sort: :created, direction: :desc}
FILTER_AFTER = Time.parse('2015-05-18 00:00:00 UTC')
client = Octokit::Client.new(access_token: ACCESS_TOKEN)
repositories = client.repositories.map(&:full_name).select{|repo| repo.start_with?(ORGANIZATION_NAME)}
@thephw
thephw / iphone.css
Created September 28, 2012 02:56
Project Q iPhone4 Media Query Quickfix
/* iPhone 4 */
@media
only screen and (-webkit-min-device-pixel-ratio : 1.5),
only screen and (min-device-pixel-ratio : 1.5) {
/* Styles */
#centercol {
width: 450px;
}
}
@thephw
thephw / foobar.rb
Created October 28, 2012 06:15
Proper After Initialize
# == Schema Information
#
# Table name: foobars
#
# id :integer not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
# name :string(255) not null
# baz :string(255)
@thephw
thephw / .bashrc
Last active October 13, 2015 18:28
Kittenify-Rails lets you easily swap out your placeholder images in from placehold it with kittens via a view helper. Sexy hotness. And seriously cute.
export KITTENIFY=1
@thephw
thephw / colorize.rb
Created December 13, 2012 15:44
Semi-graceful seeds...
# config/initializers/colorize.rb
## Just for prettier output
class String
def colorize(color, options = {})
background = options[:background] || options[:bg] || false
style = options[:style]
offsets = ["gray","red", "green", "yellow", "blue", "magenta", "cyan","white"]
styles = ["normal","bold","dark","italic","underline","xx","xx","underline","xx","strikethrough"]
start = background ? 40 : 30