Skip to content

Instantly share code, notes, and snippets.

View maliabadi's full-sized avatar

Matt Aliabadi maliabadi

  • None
  • Seattle, WA
View GitHub Profile
@maliabadi
maliabadi / gist:5916fb8ab3ffdbc6ef58
Created September 17, 2014 02:46
solr_segment_file_parser.py
import bitstring
from sys import argv
class SegmentsFile(object):
def __init__(self, path):
self.stream = bitstring.ConstBitStream(filename=path)
def read_32(self):
return self.stream.read('uint:32')
include Math
class FrequencyDistribution
attr :samples, :data
def initialize samples=[]
@data = {}
samples.each(&method(:add))
end
@maliabadi
maliabadi / htail.rb
Created January 17, 2014 23:04
script to tail robut log files. e.g 'ruby htail.rb http://minizord.corp.avvo.com/deploy_log/cloud_deploy_bugfix_11_15.log'
require 'open-uri'
printed = 0
begin
open(ARGV[0]) do |file|
`clear`
index = 0
file.each_line do |line|
if index > printed
print line
@maliabadi
maliabadi / desktop_scraper.rb
Created January 9, 2014 02:29
Want a bunch of harmless looking desktop backgrounds?
require 'rubygems'
require 'mechanize'
class DesktopScraper
BASE = "http://simpledesktops.com"
def destination_folder
File.dirname(__FILE__) + "/desktops"
end
@maliabadi
maliabadi / mv
Created November 5, 2013 20:21
open gem source in sublime
#!/usr/bin/env ruby
path = Dir["#{ENV['rvm_path']}/gems/#{ENV['RUBY_VERSION']}/gems/#{ARGV[0]}*"].sort.last
`subl #{path}`
class DeclarativeMessage(Message):
__metaclass__ = _DeclarativeMeta
query = None
query_rows = 1 # most common case
role = None
processor = None
domain = None
range = None
@maliabadi
maliabadi / doc2json.py
Last active December 10, 2015 23:58
Provides a local JSON dump of a remote Google Drive spreadsheet.
from json import dumps
from gdata.spreadsheet.service import SpreadsheetsService, DocumentQuery
from optparse import OptionParser
usage = "usage: python doc2json.py --email=EMAIL --pass=PASS title=TITLE --output=OUTFILE"
parser = OptionParser(usage=usage)
parser.add_option("-e", "--email",
metavar="EMAIL", help="email address for doc service")
parser.add_option("-p", "--password",
metavar="PASS", help="account password")
@maliabadi
maliabadi / file_three.rb
Created October 26, 2012 07:52
requiring gems
# this feels weird, but there's some magic here. Ruby knows where 'rubygems' is without you having to explain it with an exact path.
require 'rubygems'
# now you can you just flat-out require ANY gem you have installed! like
require 'pony'
# all of the sudden you have this really cool ruby library called 'pony' in your application's object space! And you can do shit like this:
Pony.mail({
:to => 'matt@cutt.com',
@maliabadi
maliabadi / file_two.rb
Created October 26, 2012 07:45
File Two
# just assuming that 'file_one.rb' is in your desktop directory.
# when you require a file, sometimes you have to specify the exact path of the file you want
require '/Users/jen/Desktop/file_one.rb'
# Now, all of that shit that was in file_one.rb, is in this file's object space.
# So i can do things like.
people.each do |person|
puts "#{person.first_name} is #{person.youth} years old"
@maliabadi
maliabadi / file_one.rb
Created October 26, 2012 07:38
File One
class Person
attr_accessor :youth, :last_name, :first_name
def initialize(first, last, age)
@youth = age
@first_name = first
@last_name = last
end
end