Skip to content

Instantly share code, notes, and snippets.

@jamesgecko
jamesgecko / with-fire-osx.py
Last active February 12, 2016 21:30
Is your [whatever] spin-locking a lot? Do you frequently open `top` just to terminate the process using all of the CPU? Behold, the magic of home automation.`pip install envoy`, then put this script in your path and `chmod +x` it.Note that this was a quick hacky thing built for the default top in Ubuntu. The man page says the columns should be c…
#! /usr/bin/env python
import envoy
def main():
r = envoy.run('top -l 2 -n 1 -o cpu -stats pid,command,cpu')
top_app = r.std_out.split('\n')[25].split()
pid = top_app[0]
process_name = ' '.join(top_app[1:-1]).strip() # Process names can can contain spaces
cpu = float(top_app[-1])
if cpu > 90:
function gpt
set before_gems (md5 Gemfile)
set before_migrations (ls -l ./db/migrate | wc -l)
git pull tapjoy master
set after_gems (md5 Gemfile)
set after_migrations (ls -l ./db/migrate | wc -l)
if [ $before_gems != $after_gems ]
bundle install
end
@jamesgecko
jamesgecko / gist:4123029
Created November 21, 2012 04:30
TimeWithZone oddity
[49] pry(main)> a = Time.zone.now
=> Wed, 21 Nov 2012 04:28:07 UTC +00:00
[50] pry(main)> b = a.to_s
=> "2012-11-21 04:28:07 UTC"
[51] pry(main)> c = Time.zone.parse(b)
=> Wed, 21 Nov 2012 04:28:07 UTC +00:00
[52] pry(main)> a == c
=> false
[57] pry(main)> a.class
=> ActiveSupport::TimeWithZone
a = nil
def foobar
a = 'meh'
end
foobar
puts a
@jamesgecko
jamesgecko / drawing.py
Created September 5, 2012 00:04
Drawing stuff
#!/usr/bin/env python
import os, sys, random, time, math
import pygame
from pygame.locals import *
pygame.init()
screen = pygame.display.set_mode((510, 510))
pygame.display.set_caption('Drawing')
background = pygame.Surface(screen.get_size())
@jamesgecko
jamesgecko / install.sh
Created June 16, 2012 20:38
Setup Ruby with rbenv on Ubuntu 12.04
# Dependencies (swiped from RVM)
sudo apt-get install build-essential bison openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev
# rbenv
cd
git clone git@github.com:sstephenson/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
# ruby-build
mkdir -p ~/.rbenv/plugins
@jamesgecko
jamesgecko / loadAddressInfo.rb
Created May 23, 2012 20:31
Load address info
# Public: Split an address string into structured data
# If you want structured data, don't let the user enter it unstructured!
# This function won't work for everything
#
# Returns a Hash containing :address, :name, :street, :zip, :state, and :city
def split_address(address_string)
result = {}
address = address_string.split("\n")
result[:name] = address[0]
result[:street] = address[1]
PS C:\Users\denton\code\portal> jruby --1.9 .\app.rb
[2012-05-16 12:15:15] INFO WEBrick 1.3.1
[2012-05-16 12:15:15] INFO ruby 1.9.2 (2012-02-22) [java]
== Sinatra/1.3.2 has taken the stage on 4567 for development with backup from WEBrick
[2012-05-16 12:15:15] INFO WEBrick::HTTPServer#start: pid=6820 port=4567
JRuby limited openssl loaded. http://jruby.org/openssl
gem install jruby-openssl for full support.
I, [2012-05-16T12:15:16.489000 #6820] INFO -- : (0.057000s) SELECT CAST(SERVERPROPERTY('ProductVers
ion') AS varchar)
I, [2012-05-16T12:15:16.560000 #6820] INFO -- : (0.057000s) SELECT TOP (1) * FROM [POLICYS] WHERE (
PS C:\Users\denton\code\portal> jruby --1.9 .\app.rb
[2012-05-16 12:24:12] INFO WEBrick 1.3.1
[2012-05-16 12:24:12] INFO ruby 1.9.2 (2012-02-22) [java]
== Sinatra/1.3.2 has taken the stage on 4567 for development with backup from WEBrick
[2012-05-16 12:24:12] INFO WEBrick::HTTPServer#start: pid=7092 port=4567
JRuby limited openssl loaded. http://jruby.org/openssl
gem install jruby-openssl for full support.
I, [2012-05-16T12:24:14.318000 #7092] INFO -- : (0.057000s) SELECT CAST(SERVERPROPERTY('ProductVers
ion') AS varchar)
I, [2012-05-16T12:24:14.389000 #7092] INFO -- : (0.058000s) SELECT TOP (1) * FROM [POLICYS] WHERE (
diff -r f5875cdc7efe Gemfile
--- a/Gemfile Mon May 07 10:42:22 2012 -0500
+++ b/Gemfile Mon May 07 10:45:09 2012 -0500
@@ -5,4 +5,4 @@
gem 'sequel'
gem 'coffee-script'
-gem 'therubyrhino'
\ No newline at end of file
+gem 'therubyrhino'