Skip to content

Instantly share code, notes, and snippets.

View djbender's full-sized avatar
🕵️‍♂️

Derek Bender djbender

🕵️‍♂️
View GitHub Profile
@jodosha
jodosha / lotus_presenter.rb
Last active August 29, 2015 13:57
A Lotus::View sneak peek: Lotus::Presenter
module Lotus
module Presenter
def initialize(object)
@object = object
end
protected
def method_missing(m, *args, &blk)
if @object.respond_to?(m)
@object.__send__ m, *args, &blk
@jodosha
jodosha / explanation.md
Last active August 29, 2015 14:00
Lotus::Repository: class vs instance methods

Given that an adapter brings its own query API, the implementation of the finders depends on the interface of the current adapter's query.

class ArticleRepository
  include Lotus::Repository

  def self.most_recent(limit = 5)
    query do
      desc(:created_at)
    end.limit(limit)
@tomstuart
tomstuart / gist:4382332089a8402bf475
Created April 30, 2014 12:59
Person#age gives the wrong answer for a person who hasn’t had their birthday yet this year
require 'active_support/time'
require 'active_support/testing/time_helpers'
require 'rspec/expectations'
include ActiveSupport::Testing::TimeHelpers
include RSpec::Matchers
class Person < Struct.new(:birthday)
def age
Date.today.year - birthday.year
end
class @Reloader
constructor: (@selector = '.wrapper', @path, @interval = 2000) ->
@start()
start: =>
@timer = setInterval(@fetch, @interval)
stop: =>
clearInterval(@timer)
@mbj
mbj / segfault.rb
Last active August 29, 2015 14:07
segfault.rb - Intentionally crash ruby
require 'ffi'
module Segfault
extend FFI::Library
ffi_lib 'ruby'
attach_function :rb_bug, [:string, :varargs], :void
end # Segfault
Segfault.rb_bug('%s', :string, 'test bug')
@jewelia
jewelia / gist:0b8f26e91f2818bef460
Last active August 29, 2015 14:15
3 Great Engineering Management Talks from 2014

General key themes:

  • Hiring is really hard. You’re not just hiring a “Rails Engineer” or a “Python Programmer” you’re hiring someone who can help you change the world. Tell them why! Talk about the hard problems you’re solving. 2/3 of these talks give ideas and insight into hiring from sourcing to actual interview processes.

  • Rewriting systems is hard. People think they are going to replace their broken down horse and buggie with a bullet train and this often ends up in disaster. Successful rewrites require an incremental approach that takes months/years and often runs way over schedule. 2/3 of these talks go over how to handle rewrites not only from a high level technical perspective but a cultural/management perspective as well.

Two Developers, Many Lines of Code, and A Campaign that Made History

Harper Reed (CTO of Obama for America, now CEO of Modest) and Dylan Richard (Director of Eng of Obama for America, now CTO of Modest)

# Basic text search with relevancy for MongoDB.
# See http://blog.tty.nl/2010/02/08/simple-ranked-text-search-for-mongodb/
# Copythingie 2010 - Ward Bekker - ward@tty.nl
#create (or empty) a docs collection
doc_col = MongoMapper.connection.db('example_db').collection('docs')
doc_col.remove({})
#add some sample data
doc_col.insert({ "txt" => "it is what it is"})
require 'rubygems'
puts ENV["GEM_HOME"]
require 'mongoid'
require 'mongoid/version'
puts "Using Mongoid: #{Mongoid::VERSION}"
Mongoid.master = Mongo::Connection.new.db("mongoid_playground")
class Animal
class RawRenderer < WillPaginate::LinkRenderer
def prepare col, opt, template
@collection = col
@options = opt
@options[:container] = nil
@template = template
@total_pages = @collection.total_pages
end
@djbender
djbender / pthread in eclipse
Created November 17, 2010 03:35
I assume MinGW installed.
I assume MinGW installed.
click Project -> Properties
C/C++ Build -> Settings -> [Tool Settings] -> MinGW C Linker (maybe be different, e.g. "GNU C/C++ Linker")
- Libraries - add the library: pthread
- Miscellaneous - add the linker flag: -lpthread