Skip to content

Instantly share code, notes, and snippets.

# 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)
#!/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
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
input = ARGF.read
# Split on commas
values = input.split(/\s*,\s*/)
# Unique
values.uniq!
#!/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
tail -f rails.log | awk '/Completed in/{print $8"\t"$9" "$10"\t"$20"\t"$22 }'
#!/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]]
@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

Keybase proof

I hereby claim:

  • I am jwarchol on github.
  • I am jwarchol (https://keybase.io/jwarchol) on keybase.
  • I have a public key whose fingerprint is 26C7 0A50 144D F56E ED6E 4E87 D940 AD76 7C70 0F12

To claim this, I am signing this object:

@jwarchol
jwarchol / README.md
Created February 21, 2015 14:17
Getting a Pentax K-r working on Raspberry Pi with pktriggercord-cli

When trying to use pktriggercord with a Pentax K-r I was unable to get it mounting via USB. I'd get lines like this over and over in /var/log/syslog:

Feb 21 14:11:12 raspberrypi kernel: [  996.673083] usb 1-1.2: new high-speed USB device number 49 using dwc_otg
Feb 21 14:11:13 raspberrypi kernel: [  996.933126] usb 1-1.2: new high-speed USB device number 50 using dwc_otg
Feb 21 14:11:13 raspberrypi kernel: [  997.193121] usb 1-1.2: new high-speed USB device number 51 using dwc_otg

When looking at other USB problems people had documented solutions for with the Pi I found that turning the USB down from hi-speed to full-speed helped in some cases. To do that edit /boot/cmdline.txt and add this to the end and reboot