Skip to content

Instantly share code, notes, and snippets.

@axgle
axgle / sync.Pool.md
Last active December 18, 2022 09:56

What is sync.Pool in golang and How to use it

sync.Pool (1/2)

Many Go libraries include custom thread-safe free lists, like this:

var objPool = make(chan *Object, 10)

func obj() *Object {

select {

@HeroicEric
HeroicEric / rspec_helper_example.md
Created April 2, 2014 14:41
An example of how to create a RSpec test helper

RSpec Helper Example

Here's an example of a rspec test helper that will let you sign in as a given user.

Create spec/support/helpers/authentication.rb with the following:

module Helpers
  module Authentication
    def sign_in_as(user)
ruby -rwebrick -e'WEBrick::HTTPServer.new(Port: 8000, DocumentRoot: Dir.pwd).start'
module Net
class HTTP
alias_method '__initialize__', 'initialize'
def initialize(*args,&block)
__initialize__(*args, &block)
ensure
@debug_output = $stderr ### if ENV['HTTP_DEBUG']
end
end
['mysql2', 'sequel', 'pp'].each(&method(:require))
DB = Sequel.connect('mysql2://root@localhost/tmp')
DB.tables.each {|t| DB.drop_table(t) }
def t(name, columns, *rows)
DB.create_table(name) do
columns.each.with_index do |column, ind|
type = rows[0][ind].class.to_s
send type, column
end
@dolzenko
dolzenko / irb_benchmark.rb
Created January 8, 2014 14:34
Automatic benchmarking in IRB (based on irb_callbacks gem code)
require 'benchmark'
module IRB
def self.before_eval
end
def self.after_eval
end
def self.around_eval(&block)
@timing = Benchmark.measure do
block.call
end
@dolzenko
dolzenko / ack-gems
Created September 5, 2013 15:31 — forked from AndrewRadev/ack-gems
#! /usr/bin/env ruby
require 'bundler'
paths = Bundler.load.specs.map(&:full_gem_path)
system("ack '#{ARGV[0]}' #{paths.join(' ')}")
@robfig
robfig / .emacs
Last active June 13, 2023 16:08
Emacs integration with goimports - https://github.com/bradfitz/goimports. Every time you save your Go code, 1. Add missing imports (standard library only), 2. Remove unnecessary imports, 3. Go fmt
;; OSX - Update the PATH to match that from the shell
(defun set-exec-path-from-shell-PATH ()
(let ((path-from-shell
(replace-regexp-in-string "[[:space:]\n]*$" ""
(shell-command-to-string "$SHELL -l -c 'echo $PATH'"))))
(setenv "PATH" path-from-shell)
(setq exec-path (split-string path-from-shell path-separator))))
(when (equal system-type 'darwin) (set-exec-path-from-shell-PATH))
;; Go mode
@dolzenko
dolzenko / hows.rb
Last active December 16, 2015 15:59
require 'stamp'
require 'text-table'
def how(ts)
hour = (ts.to_f / 3600).floor
hour % 24 + ((hour / 24 + 4).floor % 7) * 24
end
from = Time.utc(2013, 4, 7)
to = Time.utc(2013, 4, 7 + 7)
@ryansobol
ryansobol / gist:5252653
Last active February 23, 2025 06:28
15 Questions to Ask During a Ruby Interview

Originally published in June 2008

When hiring Ruby on Rails programmers, knowing the right questions to ask during an interview was a real challenge for me at first. In 30 minutes or less, it's difficult to get a solid read on a candidate's skill set without looking at code they've previously written. And in the corporate/enterprise world, I often don't have access to their previous work.

To ensure we hired competent ruby developers at my last job, I created a list of 15 ruby questions -- a ruby measuring stick if you will -- to select the cream of the crop that walked through our doors.

What to expect

Candidates will typically give you a range of responses based on their experience and personality. So it's up to you to decide the correctness of their answer.