Skip to content

Instantly share code, notes, and snippets.

@rwz
rwz / p5n.md
Last active October 24, 2021 15:09
persona 5 negotiatons

Codes:

  • L: Likes
  • D: Dislikes
  • M: Meh.

Depending on the persona for successful negotiation you need either 2 Like answers or 1 Like + 1 Meh.


@rwz
rwz / gist:14c0d8a5187b69922bb4
Last active January 28, 2019 11:42
Custom JSON types in AS 4.1+
# config/initializers/lol_json.rb
module ActiveSupport
module JSON
module Encoding
class JSONGemEncoder
BYPASS_JSONIFY = Set.new
alias_method :original_jsonify, :jsonify
@rwz
rwz / doesnt.rb
Created December 13, 2010 06:50
state_machine + delayed_job wtf
# doesn't fucking work
class Logo < ActiveRecord::Base
state_machine :state, :initial => :initial do
# here vvv
after_transition :initial => :used, :do => :test_callback
@rwz
rwz / gist:3281979
Created August 7, 2012 05:35
Rendering Jbuilder templates from within model
# this is the easiest way to use partials from model I could find so far
class Entry < AR::Base
def as_json
context = ApplicationController.new.view_context
context.render('/api/entries/entry.json', entry: self)
end
end
@rwz
rwz / wtf.rb
Last active April 26, 2017 19:00
dynamic method definition in ruby
class MyClass
def static_yield(*)
yield if block_given?
end
define_method :dynamic_yield do |*|
yield if block_given?
end
define_method :dynamic_yield_fix do |*, &block|
my_string.scan(/[a-z\d]+/).each_with_object(Hash.new(0)){ |e, a| a[e] += 1 }
@rwz
rwz / my_hash.rb
Last active January 2, 2016 09:39
An interesting Ruby problem
class MyHash < Hash
undef_method :fetch
def fetch(*)
# your code goes here
end
end
require "rspec/autorun"
@rwz
rwz / bm.rb
Created January 3, 2014 20:49
I18N east slavic pluralization benchmark
require "benchmark/ips"
require "set"
OLD_CODE = ->(n){
mod10 = n % 10
mod100 = n % 100
if mod10 == 1 && mod100 != 11
:one
elsif [2, 3, 4].include?(mod10) && ![12, 13, 14].include?(mod100)
@rwz
rwz / gist:7636420
Created November 25, 2013 04:35
rbenv install 2.0.0-p353
/var/folders/50/nmb34mx94js1fd1z_s5fl8pr0000gn/T/ruby-build.20131124231727.32309 ~
HTTP/1.1 200 OK
Content-Type: binary/octet-stream
Content-Length: 13572794
Connection: keep-alive
Date: Sat, 23 Nov 2013 04:24:40 GMT
Last-Modified: Fri, 22 Nov 2013 05:12:40 GMT
ETag: "78282433fb697dd3613613ff55d734c1"
Accept-Ranges: bytes
Server: AmazonS3

ruby-1.9.3-p392 cumulative performance patch for rbenv

(I guarantee nothing. No warranty I am not responsible blah blah blah. Seems to work great for me so far. Thanks to Tyler Bird who I forked this from.)

This installs a patched ruby 1.9.3-p392 with the railsexpress patchsets: https://github.com/skaes/rvm-patchsets

Requirements