Skip to content

Instantly share code, notes, and snippets.

View tjsingleton's full-sized avatar

TJ Singleton tjsingleton

View GitHub Profile
@tjsingleton
tjsingleton / default.rb
Created May 22, 2012 20:36
recipe to specify rack version
#
# Cookbook Name:: rack_version
# Recipe:: default
if ['solo', 'app_master', 'app'].include?(node[:instance_role])
gem_package "rack" do
version "1.4.1"
action :remove
end
@tjsingleton
tjsingleton / detect_password.rb
Created May 12, 2012 22:58
Dropquest 2012, Step 1
# The product of the first two digits is 24.
# The fourth digit is half of the second digit.
# The sum of the last two digits is the same as the sum of the first and third digits.
# The sum of all the digits is 26.
# The second and third digits add up to the last digit.
def number_to_digits(n)
n.to_s.split("").map(&:to_i)
end
<?php
function array_to_attributes($atts) {
$attribute_format = '%s="%s"';
$attributes = array();
if (is_array($atts)) {
foreach ($atts as $key => $value) {
$attributes[] = sprintf($attribute_format, $key, $value);
}
}
@tjsingleton
tjsingleton / Chef Solo Bootstrap with Ruby 2.2.2
Last active November 5, 2021 21:41 — forked from nyxwulf/Chef Bootstrap Ruby 1.9.3-p194
Chef Solo Bootstrap with Ruby 2.2.2
#!/usr/bin/env bash
apt-get -y update
apt-get -y upgrade
apt-get -y install build-essential zlib1g-dev libssl-dev libreadline-gplv2-dev libyaml-dev libffi-dev libjemalloc-dev
apt-get -y install autoconf curl bzip2
apt-get -y autoremove
apt-get -y clean
cd /usr/local/src
curl http://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.2.tar.gz
>> start_at = Time.now
=> 2012-02-11 14:20:51 -0500
>> end_at = 8.hours.from_now
=> Sat, 11 Feb 2012 22:20:54 EST -05:00
>> shift_duration = (end_at - start_at).to_i
=> 28802
>> shift_intervals = shift_duration/15.minutes
=> 32
>> break_starts = []; shift_intervals.times{|n| break_starts << (break_starts.last || start_at) + (15.minutes * n)}
=> 32
Point = Struct.new(:x, :y)
point = Point.new do |n|
n.x = 1
n.y = 2
end
Point = KeywordStruct.new :x, :y
Point.new(x: 1, y: 2)
@tjsingleton
tjsingleton / default_perm_filter.rb
Created September 14, 2011 16:48
Given a list of paths, it sets default permissions.
#!/usr/bin/env ruby
require "pathname"
class DefaultPermissionFilter
DEFAULTS = {
"directory" => 0755,
"file" => 0644
}
def run(path)
@tjsingleton
tjsingleton / 1_benchmark.rb
Created August 9, 2011 18:14
cost of module inclusion
require "benchmark"
N = 1_000_000
module SmallExtension
def a
end
def b
end
import java.awt.*;
import javax.swing.*;
public class AnimatedScreenCapture extends JFrame {
JLabel label;
Robot robot;
Rectangle screenRect;
int scaleX;