Skip to content

Instantly share code, notes, and snippets.

View bhuga's full-sized avatar

Ben Lavender bhuga

View GitHub Profile
require 'rubygems'
require 'ruby-debug'
require 'spira'
require 'rdf/rdfxml'
require 'sparql/client'
class Actor
include Spira::Resource
@bhuga
bhuga / sparql-client-refactor.rb
Created February 1, 2011 18:33
Updates to SPARQL client to allow parsing with other tools, if so wished.
require 'sparql/client'
require 'rest_client'
sparql = SPARQL::Client.new("http://dbpedia.org/sparql")
# existing functionality:
p sparql.query("select distinct ?Concept where {[] a ?Concept}").inspect
# now equivalent to:
response = RestClient.post 'http://dbpedia.org/sparql', { :query => "select distinct ?Concept where {[] a ?Concept}" }, :content_type => 'application/x-www-form-urlencoded', :accept => 'application/sparql-results+json'
@bhuga
bhuga / client-assert.rb
Created February 19, 2011 22:08
Demonstrates assertions, server
#!/usr/bin/env ruby
require 'ffi-rzmq'
#IPC_SOCKET = "ipc:///tmp/assert-demo.zmq"
IPC_SOCKET = 'tcp://localhost:5555'
@sender_context = ZMQ::Context.new(2)
send_socket = @sender_context.socket(ZMQ::REQ)
second_send_socket = nil
send_socket.connect(IPC_SOCKET)
$ ->
class window.Chat extends Backbone.Model
class window.ChatList extends Backbone.Collection
model: Chat
window.chats = new ChatList
class window.ChatView extends Backbone.View
tagName: 'li'
@bhuga
bhuga / Guardfile
Created February 3, 2012 19:26
Can't believe this one took me so long to figure out.
guard 'spork', :rspec_env => { 'RAILS_ENV' => 'test' } do
watch('Gemfile.lock')
watch('spec/spec_helper.rb')
watch('config/application.rb')
watch('config/environment.rb')
watch(%r{^config/environments/.+\.rb$})
watch(%r{^config/initializers/.+\.rb$})
watch(%r{^spec/support/.+\.rb$})
watch(%r{^spec/factories/.+\.rb$})
# watch(%r{^spec/factories/.+\.rb$}) # Uncomment when you have a large amount of factories
@bhuga
bhuga / attribute_filter.rb
Created March 4, 2012 19:55 — forked from dpickett/attribute_filter.rb
attribute filter concept for mass assignment
class User < ActiveRecord::Base
protection_strategy :whitelist do
only :first_name, :last_name, :login, :password, :password_confirmation
end
protection_strategy :blacklist do
except :encrypted_password
end
end
u = User.new({protected_attribute: "blah", first_name: "John"}, filter: :whitelist)
@bhuga
bhuga / hybrid_authenticatable.rb
Created November 9, 2012 22:23 — forked from spullen/devise_create_user.rb
HybridAuthenticatable 2
class DeviseCreateUsers < ActiveRecord::Migration
def change
create_table(:users) do |t|
## Database authenticatable
t.string :username, :null => false, :default => ""
t.string :email, :null => false, :default => ""
t.string :encrypted_password, :null => false, :default => ""
## Recoverable
t.string :reset_password_token
@bhuga
bhuga / anything.rb
Last active August 29, 2015 13:57
Sane sawyer inspect for octokit
class Sawyer::Resource
def to_attrs
hash = self.attrs.clone
hash.keys.each do |k|
if hash[k].is_a?(Sawyer::Resource)
hash[k] = hash[k].to_attrs
end
end
hash
end
@bhuga
bhuga / gist:9631068
Created March 18, 2014 22:21
heroku available fonts
Path: /usr/lib/ImageMagick-6.5.7/config/type-ghostscript.xml
Font: AvantGarde-Book
family: AvantGarde
style: Normal
stretch: Normal
weight: 400
glyphs: /usr/share/fonts/type1/gsfonts/a010013l.pfb
Font: AvantGarde-BookOblique
family: AvantGarde
style: Oblique
@bhuga
bhuga / keybase.md
Created March 25, 2014 21:46
keybase.md

Keybase proof

I hereby claim:

  • I am bhuga on github.
  • I am bhuga (https://keybase.io/bhuga) on keybase.
  • I have a public key whose fingerprint is 73A5 ACF2 703C 88E3 A25B 8D88 4E78 3A18 06B9 07E8

To claim this, I am signing this object: