Skip to content

Instantly share code, notes, and snippets.

@DAddYE
DAddYE / script.sh
Last active December 14, 2015 05:29
Open SSL problem with Ruby 2.0 ?
# Previous one is unsafe
you should take a look at this: https://github.com/raggi/openssl-osx-ca
anonymous
anonymous / gist:3753571
Created September 20, 2012 02:10
@ChristinGorman gave this talk at JavaZone: https://vimeo.com/49484333 It's quite good, short, energetic, enthusiastic,
intelligent, and completely misses the point.
While it's true that the code she produces is much better than the original, and is quite easy to understand; it fails one
critical test. It's not polite.
Polite code is like a well written newspaper article. It allows you to bail out early. A well written article has a
headline, a synopsis, and a set of paragraphs that begin with the high level concepts and get more and more detailed as you
read through the article. At any point you can decide: "I get it! I don't need to read further." Indeed, this is how most
people read newspapers or magazines. The articles are polite, because they allow you to get out quickly.
@nhance
nhance / method_logger.rb
Created September 6, 2012 12:58
Rails compatible method logging. Use this to log all calls to instance methods of a class to the log.
Model.new.foo
@andkerosine
andkerosine / raskell.rb
Created August 15, 2012 05:56
Haskell-like list comprehensions in Ruby
$stack, $draws = [], {}
def method_missing *args
return if args[0][/^to_/]
$stack << args.map { |a| a or $stack.pop }
$draws[$stack.pop(2)[0][0]] = args[1] if args[0] == :<
end
class Array
def +@
@coreyhaines
coreyhaines / use_validation_helpers.rb
Created August 9, 2012 15:52
Thoughts on ActiveModel::Validator as a validation service
# I love the helpers, they help to make the intention clear.
# I want to be able to do this. That is, using the validation helpers inside a validator object,
# rather than having to do manual validation.
class EmployeeValidator < ActiveModel::Validator
def validate(record)
record.validates_presence_of :email
end
end
@swannodette
swannodette / gist:3217582
Created July 31, 2012 14:52
sudoku_compact.clj
;; based on core.logic 0.8-alpha2 or core.logic master branch
(ns sudoku
(:refer-clojure :exclude [==])
(:use clojure.core.logic))
(defn get-square [rows x y]
(for [x (range x (+ x 3))
y (range y (+ y 3))]
(get-in rows [x y])))
require 'fiddle'
require 'minitest/autorun'
class RubyVM
class InstructionSequence
address = Fiddle::Handle::DEFAULT['rb_iseq_load']
func = Fiddle::Function.new(address, [Fiddle::TYPE_VOIDP] * 3, Fiddle::TYPE_VOIDP)
define_singleton_method(:load) do |data, parent = nil, opt = nil|
func.call(Fiddle.dlwrap(data), parent, opt).to_value
@bsodmike
bsodmike / pryrc.rb
Created June 15, 2012 22:37
Pry config with tweak for Rails 3.2+ to add support for `reload!` etc. (console helpers)
Pry.config.editor = "mvim"
# Load plugins (only those I whitelist)
Pry.config.should_load_plugins = false
Pry.plugins["doc"].activate!
# Launch Pry with access to the entire Rails stack.
# If you have Pry in your Gemfile, you can pass: ./script/console --irb=pry instead.
# If you don't, you can load it through the lines below :)
rails = File.join Dir.getwd, 'config', 'environment.rb'
@jboner
jboner / latency.txt
Last active November 16, 2024 21:28
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@justinko
justinko / Plea.markdown
Created May 30, 2012 19:40
Am I doing it wrong?

Dear Rubyists,

I just lost a contract because of my code in a Rails project.

The specific code in question is related to a "posting a comment" feature. Here are the details:

In this project, "posting a comment" does not simply entail inserting a row into the database. It involves a procedure to yes, insert a row, but also detect its language, check for spam, send emails, and "share" it to Twitter and Facebook. I believe this algorithm should be encapsulated. I do not believe it belongs in a controller or a model. I do not believe Active Record callbacks should be used.

The "senior developer", whom is the stake holder's right hand man, said this: