Skip to content

Instantly share code, notes, and snippets.

@jwarchol
jwarchol / gist:9020
Created September 5, 2008 20:32 — forked from anonymous/gist:9016
class Update < ActiveRecord::Base
belongs_to :job_id, :foreign_key => 'job_id', :class_name => 'Job'
file_column :attachment
def authorized_for_destroy?
return false if new_record?
return Update.count(:conditions => ["created_at > ?", self.created_at]) == 0
end
#!/usr/bin/env ruby
def main(args)
memory = {}
post_sub_regexp = /\(\([^)]+\)\)/
input = IO.read(args[0])
while matches = input.match(/\(\(([^)]+)\)\)/) do
if matches[1] =~ /:/
var, prompt = matches[1].split(":")
elsif memory[matches[1]]
tail -f rails.log | awk '/Completed in/{print $8"\t"$9" "$10"\t"$20"\t"$22 }'
#!/bin/bash
#
# This file echoes a bunch of color codes to the
# terminal to demonstrate what's available. Each
# line is the color code of one forground color,
# out of 17 (default + 16 escapes), followed by a
# test use of that color on all nine background
# colors (default + 8 escapes).
#
# Author: Giles Orr
#!/usr/bin/env ruby
input = ARGF.read
# Split on commas
values = input.split(/\s*,\s*/)
# Unique
values.uniq!
mysql> select * from entries where phone_id = 40;
+-----+----------+-------+---------+---------------------+---------------------+---------+
| id | phone_id | miles | gallons | created_at | updated_at | mpg |
+-----+----------+-------+---------+---------------------+---------------------+---------+
| 209 | 40 | 33318 | 19.295 | 2009-11-26 22:07:29 | 2009-11-26 22:07:29 | NULL |
| 210 | 40 | 33631 | 16.494 | 2009-11-28 22:11:21 | 2009-11-28 22:11:21 | 18.9766 |
| 212 | 40 | 34075 | 23.642 | 2009-12-05 01:24:18 | 2009-12-05 01:24:18 | 18.7801 |
| 213 | 40 | 34302 | 14.092 | 2009-12-06 18:27:38 | 2009-12-06 18:27:38 | 16.1084 |
| 215 | 40 | 34638 | 19.022 | 2009-12-10 23:36:49 | 2009-12-10 23:36:49 | 17.6638 |
| 218 | 40 | 35097 | 24.074 | 2009-12-18 17:34:43 | 2009-12-18 17:34:43 | 19.0662 |
#!/usr/bin/env ruby
cnt = 0
loop do
puts "loop"
line = STDIN.readline
if line =~ Regexp.new(ARGV[0])
puts "\tmatch"
File.open("install-#{cnt}.txt", "w") {|f| f.write Time.now.to_s}
cnt += 1
# Calculates the domain hash part of a Google Analytics __utma cookie's value.
def domain_hash(domain_name)
domain_hash = 0
g = 0
(domain_name.size - 1).downto(0) do |i|
c = domain_name[i]
domain_hash = ((domain_hash << 6) & 268435455) + c + (c << 14)
f = {
foo: function() {
console.log("foo");
},
bar: function() {
console.log("bar");
},
foobar: function() {
this.foo();
this.bar();
@jwarchol
jwarchol / gist:1052930
Created June 29, 2011 03:15
mysql2-is-weird
$ ab -c 20 -n 500 "http://localhost:9000/?id=1"
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests