Skip to content

Instantly share code, notes, and snippets.

View the-architect's full-sized avatar
🐒
working on ... 👨🏼‍💻

Marcel Scherf the-architect

🐒
working on ... 👨🏼‍💻
View GitHub Profile
@the-architect
the-architect / PDF2PNG PDF Thumbnail Generator.rb
Created December 10, 2009 09:52
PDF2PNG PDF Thumbnail Generator
require 'rubygems'
require 'RMagick'
class Pdf2PngConverter
def initialize(*files)
files.each do |file|
pdf = Magick::ImageList.new(file)
filename = "#{File.join(File.dirname(file), File.basename(file, '.*'))}.png"
pdf[0].resize_to_fit(100,100).write(filename)
# gem install smusher:
@the-architect
the-architect / contact.rb
Created September 15, 2011 16:09
Automatically create scopes for all available state_machine states in Rails 3.1
class Contact < ActiveRecord::Base
state_machine :state, :initial => :imported do
state :imported
state :contacted
state :verified
state :prospect
state :deleted
end
@the-architect
the-architect / Gemfile
Last active December 10, 2015 09:58
Redis Pubsub test with backlog of posted messages.
Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8
source 'https://rubygems.org'
gem 'redis'
gem "hiredis"
gem "em-synchrony"
gem 'json'
@the-architect
the-architect / couchbase_attributes.rb
Created February 14, 2013 14:16
Simple object attributes that are persisted in couchbase.
module CouchbaseAttributes
module ClassMethods
def couchbase_attribute(name)
class_eval %Q{
def #{name}=(value)
Couchbase.bucket.set([couchbase_id, '#{name}'].join('::'), value)
end
def #{name}
@the-architect
the-architect / hash.rb
Created July 31, 2013 15:05
Reverse the order of a hash
class Hash
# reverses the order of a hash
# { a: 100, b: 200 }.reverse => { b:200, a:100 }
def reverse
self.class[to_a.reverse]
end
end
@the-architect
the-architect / tor_http.rb
Last active December 24, 2015 22:49
Fetch a website through Tor
# brew install tor / apt-get install tor
# follow the instructions to start the tor server
# gem install socksify
require 'socksify/http'
uri = URI.parse('http://rubyforge.org/')
# 9050 is the tor port
Net::HTTP.SOCKSProxy('127.0.0.1', 9050).start(uri.host, uri.port) do |http|
@the-architect
the-architect / hash.rb
Last active August 29, 2015 14:02
Hash#fetch with multiple keys => Hash.path
module CoreExt
module PathExtension
# this method recursively calls fetch with every key you provide
# the last key argument is used as the default value
def path(*keys)
key = keys.shift
case keys.length
when 0
@the-architect
the-architect / array_object_index_of.coffee
Created June 21, 2014 10:03
Extend Array so it handles indexOf of Angular collections properly
Array::arrayObjectIndexOf = (obj) ->
for elem, i in @
if(angular.equals(elem, obj))
return i
-1
@the-architect
the-architect / html5_placeholder_styling.scss
Created June 21, 2014 10:06
Style HTML5 placeholder text
body{
// unfortunately we need to enter each of these browser specific selectors
::-webkit-input-placeholder { font-style:italic; }
:-moz-placeholder { font-style:italic; }
::-moz-placeholder { font-style:italic; }
:-ms-input-placeholder { font-style:italic; }
}
@the-architect
the-architect / cmdstamp.sh
Last active August 29, 2015 14:03
Show the last accessed timestamp for a command line program in path
# ubuntu:
# add this to your ~/.bashrc
cmdstamp(){
which $1 | xargs stat -c '%Y'
}