Skip to content

Instantly share code, notes, and snippets.

@abronte
abronte / checker.rb
Created January 5, 2012 00:07
Machine checker
#!/usr/bin/ruby
loop do
Machine.all.each do |m|
m.alive?
puts "#{m.name} is #{m.mstatus}"
end
@home = Home.first
@desktop = Machine.find(3)
@abronte
abronte / machine.rb
Created January 5, 2012 00:26
Machine model
require 'ping'
require 'socket'
require 'net/ssh'
require 'wol.rb'
class Machine < ActiveRecord::Base
def alive?
if Ping.pingecho(self.ip, 2)
self.mstatus = "up"
@abronte
abronte / gist:2143903
Created March 21, 2012 02:49
String Distance
stringDistance: function(s1, s2) {
// sift3: http://siderite.blogspot.com/2007/04/super-fast-and-accurate-string-distance.html
if (s1 == null || s1.length === 0) {
if (s2 == null || s2.length === 0) {
return 0;
} else {
return s2.length;
}
}
@abronte
abronte / gist:2306690
Created April 5, 2012 00:03
LFTP sync
#!/bin/bash
HOST="email.com:1234"
USER="username"
PASS="password"
LCD="/path/to/local/dir"
RCD="/path/to/remote/dir"
if [ ! -e "/tmp/xfer" ]
then
touch /tmp/xfer
" Clear all types of comments
map _ :s/^\/\/\\|^--\\|^> \\|^[#"%!;]//<CR>:nohlsearch<CR>
" Add a # comment at the begining
map - :s/^/#/<CR>:nohlsearch<CR>
filetype on
augroup vimrc_filetype
autocmd!
autocmd FileType ruby call s:RubyCommenter()
autocmd FileType vim call s:VimCommenter()
augroup end
map _ :s/^\/\/\\|^--\\|^> \\|^[#"%!;]//<CR>:nohlsearch<CR>
tell application "Google Chrome"
activate
set theUrl to "http://calendar.google.com"
if (count every window) = 0 then
make new window
end if
tell window 1 to make new tab with properties {URL:theUrl}
end tell
@abronte
abronte / gist:3763216
Created September 21, 2012 18:55
BigQuery gem example
require 'bigquery'
opts = {}
opts['client_id'] = '1234.apps.googleusercontent.com'
opts['service_email'] = '1234@developer.gserviceaccount.com'
opts['key'] = '/path/to/somekeyfile-privatekey.p12'
opts['project_id'] = '54321'
opts['dataset'] = 'yourdataset'
bq = BigQuery.new(opts)
{
"error": {
"message": "Unsupported get request.",
"type": "GraphMethodException",
"code": 100
}
}
brunch new MyApp --skeleton git@github.com:abronte/brunch-with-trigger.git