Skip to content

Instantly share code, notes, and snippets.

View toch's full-sized avatar
🐱

Christophe Philemotte toch

🐱
View GitHub Profile
@toch
toch / Rakefile
Created January 19, 2016 19:52
mruby minimum Rakefile
APP_ROOT=ENV["APP_ROOT"] || Dir.pwd
# avoid redefining constants in mruby Rakefile
mruby_root=File.expand_path(ENV["MRUBY_ROOT"] || "#{APP_ROOT}/mruby")
mruby_config=File.expand_path(ENV["MRUBY_CONFIG"] || "build_config.rb")
ENV['MRUBY_ROOT'] = mruby_root
ENV['MRUBY_CONFIG'] = mruby_config
Rake::Task[:mruby].invoke unless Dir.exist?(mruby_root)
Dir.chdir(mruby_root)
load "#{mruby_root}/Rakefile"
@toch
toch / resprite.rake
Created May 3, 2013 08:55
A Rake task to generate CSS Sprites for Bootstrap-like icons
require 'sprite_factory'
namespace :assets do
desc 'recreate sprite images and css'
task :resprite => :environment do
Dir.glob('app/assets/images/icons/*.svg').each do |svg_file|
%x(convert -antialias -background transparent #{svg_file} -resize 15x14 #{File.dirname svg_file}/#{File.basename(svg_file).gsub(/\.svg\z/, ".png")} )
end
SpriteFactory.cssurl = "image-url('$IMAGE')"
@toch
toch / ArrayEqualTest
Last active December 14, 2015 02:09 — forked from vanakenm/ArrayEqualTest
Because - use eql? operator and include use == operator, you should take care of what you can obtain with a - (that use key hash to make the search) and include (that use object comparator to test)
require 'minitest/autorun'
require 'minitest/spec'
class ElementTest
attr_accessor :value
def eql?(other)
value == other.value
end
@toch
toch / define_method_vs_module_eval.rb
Last active December 12, 2015 07:14
Example of usage of benchmark-lab on JuanitoFatas/fast-ruby
require 'benchmark/lab'
def method_names(number)
number.times.map do
10.times.inject("") { |e| e << ('a'..'z').to_a.sample}
end
end
class DefineMethod
def self.def_methods(_methods)
@toch
toch / README.md
Last active November 25, 2015 22:19
A message to mruby contributors

Hi all,

It's the second year that me and Tyler are organizing the Ruby devroom at fosdem 2016. It focuses on Ruby internals and implementations. It's more about how Ruby is implemented than how it can be used. Last year we had great devs for MRI, Jruby, Rubinius, or Rubymotion. It would be wonderful to have a talk about mruby.

The CFP is open and ends on the 1st December.

Thanks for sharing it with other mruby contributors.

@toch
toch / your_host_file
Created November 6, 2015 16:02
simple maintenance page for rails + apache2
RewriteEngine On
ErrorDocument 503 /maintenance.html
RewriteCond %{REQUEST_URI} !.(css|gif|jpg|png)$
RewriteCond %{DOCUMENT_ROOT}/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ - [L,R=503]
@toch
toch / gist:3205754
Created July 30, 2012 09:07
keybinding to run uxterm from Sublime Text 2 on Linux with Shell Turtlestein package
https://github.com/misfo/Shell-Turtlestein
add the following in your User keybinding setup file: ~/.config/sublime-text-2/Pacakges/User/Default (Linux).sublime-keymap
[
{"keys": ["shift+ctrl+alt+c"], "command": "subprocess_in_cwd", "args": {
"cmd": ["uxterm", "/bin/bash"]
} }
]
@toch
toch / Pancake.md
Created September 28, 2015 08:27
Pancake Recipe

Pancakes (about 8)

Ingredient

  • 200g Philadelphia light Cream Cheese
  • 1 egg
  • 230ml semi-skimmed milk
  • 200g flour
  • 8g bakery yeast
  • 1/2 tea spoon salt
@toch
toch / gist:d1f83893af024c94581e
Created July 16, 2015 16:39
keybase verfication
### Keybase proof
I hereby claim:
* I am toch on github.
* I am toch (https://keybase.io/toch) on keybase.
* I have a public key whose fingerprint is 85EF 645A 76A2 4150 55D5 109A AAE6 0C3E E979 07D7
To claim this, I am signing this object:
@toch
toch / trace_calls.rb
Last active September 8, 2015 14:50
Decorate any method in Ruby to get its call stack
def trace_calls_on
scope = {}
trace = TracePoint.new(:call, :line) do |tp|
case tp.event
when :call then puts "#{tp.path}:#{tp.lineno} #{tp.defined_class}::#{tp.method_id} " \
"called from #{scope[:path]}:#{scope[:lineno]} #{scope[:class]}::#{scope[:method_id]}"
when :line then scope = {
event: :line,
lineno: tp.lineno,
path: tp.path,