Skip to content

Instantly share code, notes, and snippets.

@sdsykes
sdsykes / gist:913210
Created April 11, 2011 07:53
background jobs
Here's what I do:
This is Rails 2
pid = fork do
%x{RAILS_ENV=#{Rails.env} #{RAILS_ROOT + "/script/runner"} '#{script}'}
exit!
end
Process.detach pid
@sdsykes
sdsykes / gist:1047422
Created June 26, 2011 09:04
OSX 10.6.7 python upgrade twisted fails
$ sudo easy_install --upgrade twisted
Password:
install_dir /Library/Python/2.6/site-packages/
Searching for twisted
Reading http://pypi.python.org/simple/twisted/
Reading http://twistedmatrix.com/
Reading http://tmrc.mit.edu/mirror/twisted/Twisted/10.0/
Reading http://www.twistedmatrix.com
Reading http://twistedmatrix.com/products/download
Reading http://tmrc.mit.edu/mirror/twisted/Twisted/8.2/
@sdsykes
sdsykes / gist:1184568
Created August 31, 2011 20:06
move space
on run argv
set space_number to item 1 of argv
tell application "System Events"
keystroke space_number using {control down}
end tell
end run
@sdsykes
sdsykes / gist:1184640
Created August 31, 2011 20:33
scriptingbridge sending keystroke with control key
def four_char_code(s)
(s[0].ord << 24) + (s[1].ord << 16) + (s[2].ord << 8) + s[3].ord
end
system = SBApplication.applicationWithBundleIdentifier("com.apple.SystemEvents")
system.send(:"keystroke:using:", space_number.to_s, four_char_code('Kctl'))
@sdsykes
sdsykes / mongoid.rb
Created October 8, 2011 08:17
Fix for mongoid uninitialized constant errors from loading everything in lib in mongoid.rb in initializers
# initializers/mongoid.rb
# for when files in lib depend on or inherit from other files in lib
def do_require(file)
begin
require file
rescue NameError => e
e.message =~ /constant (\w+::)*(\w+)$/
if $2
do_require($2.underscore)

Keybase proof

I hereby claim:

  • I am sdsykes on github.
  • I am sdsykes (https://keybase.io/sdsykes) on keybase.
  • I have a public key whose fingerprint is 8083 1053 7ED3 36B7 4B12 A80B 90A5 BAEA 6D05 D980

To claim this, I am signing this object:

@sdsykes
sdsykes / invert.rb
Last active August 29, 2015 14:04
A quick and dirty solver for Inverter http://gorried.github.io/inverter/game.html
$size = ARGV[0].to_i
if $size <= 0
puts "Supply numeric level (grid size) as an argument"
exit
end
def show(placement)
0.upto($size - 1) do |x|
@sdsykes
sdsykes / gist:5c2c0c2a41396aead3b7
Last active December 29, 2022 13:01
Windows on a space (using private CGS)
/// header
id CGSCopyManagedDisplaySpaces(int conn);
int _CGSDefaultConnection();
id CGSCopyWindowsWithOptionsAndTags(int conn, unsigned owner, NSArray *spids, unsigned options, unsigned long long *setTags, unsigned long long *clearTags);
// code
int spaceNumber = 0; // the space you want to get the windows for. numbering starts at 0.
require 'totalspaces2'
TotalSpaces2.move_to_space(ARGV[0].to_i)
@sdsykes
sdsykes / down.rb
Last active September 17, 2015 12:44
Scripts to move each direction for TotalSpaces2
require 'totalspaces2'
current = TotalSpaces2.current_space
spaces = TotalSpaces2.number_of_spaces
columns = TotalSpaces2.grid_columns
new_space = current + columns
if new_space <= spaces
TotalSpaces2.move_to_space(new_space)
end