Skip to content

Instantly share code, notes, and snippets.

2.0.0 (main):0 > Genre.new.my_transation_method
nil
2.0.0 (main):0 > Genre.last
nil
2.0.0 (main):0 >
@morhekil
morhekil / 1-good.rb
Created May 19, 2013 02:54
Ruby threads and processes fun. Creating new thread, then forking off a child inside it and waiting for the child to finish. It works when using fork with a block argument, and it works when not creating a thread. But it doesn't work (hangs) when creating a thread and using fork with if/else syntax.
t = Thread.new do
pid = fork do
puts "I'm the child #{Process.pid}"
raise 'hello'
end
puts "Thread #{Thread.current.inspect}, pid: #{pid.inspect}"
puts "I'm the parent #{Process.pid}"
Process.waitpid(pid)
end
t = Thread.new do
pid = fork do
raise 'hello'
end
Process.waitpid(pid)
end
t.join
@morhekil
morhekil / exception.rb
Created May 19, 2013 01:38
Ruby - exception in the forked process
child = fork do
raise RuntimeError, "testing child exception"
end
pid, status = Process.wait2 child
puts status.inspect
@morhekil
morhekil / rails2_zurb_foundation.rb
Created January 14, 2013 11:24
How to integrate Zurb Foundation with Rails 2.3 project. Requires a backport of asset pipeline to Rails 2. http://foundation.zurb.com/ https://github.com/grosser/rails2_asset_pipeline
begin
require 'zurb-foundation'
rescue MissingSourceFile
# doing a rescue here as Zurb is Rails3-oriented, and so it will try to load
# Rails 3 style generators, etc. We don't need that, we only need the
# frameworks and includes
end
# Add all registered frameworks to Sass's load path to make them available
# through @imports
@morhekil
morhekil / mysql_grants_dump.sh
Created January 6, 2013 08:06
shell script to dump existing MySQL privileges as GRANT commands
#!/usr/bin/bash
mysql -B -N $@ -e "SELECT DISTINCT CONCAT(
'SHOW GRANTS FOR ''', user, '''@''', host, ''';'
) AS query FROM mysql.user" | \
mysql $@ | \
sed 's/\(GRANT .*\)/\1;/;s/^\(Grants for .*\)/## \1 ##/;/##/{x;p;x;}'
@morhekil
morhekil / app_data.rb
Created September 12, 2012 11:54 — forked from railyboy/app_data.rb
Loading .yml configuration data with the code from http://speakmy.name/2011/05/29/simple-configuration-for-ruby-apps
module AppData
#require 'deep_symbolizable'
# again - it's a singleton, thus implemented as a self-extended module
extend self
@_settings = {}
attr_reader :_settings
@morhekil
morhekil / LICENSE
Last active January 22, 2017 22:12
Implementation of deep symbolization of keys for Ruby hashes
The MIT License (MIT)
Copyright (c) 2015 Oleg Ivanov http://github.com/morhekil
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@morhekil
morhekil / tidy.patch
Created November 7, 2010 18:59
Tidy patch
--- tidybuf.rb 2007-04-10 09:09:01.000000000 -0500
+++ tidybuf.rb.patched 2007-04-10 09:08:55.000000000 -0500
@@ -11,6 +11,7 @@
# Mimic TidyBuffer.
#
TidyBuffer = struct [
+ "int* allocator",
"byte* bp",
"uint size",
"uint allocated",
@morhekil
morhekil / 0001-fix-lighttpd15-build-on-mac-os-x.patch
Created June 20, 2010 12:34
Patch for lighttpd web server to build 1.5 head on Mac OS X
From 89c418f2734e89e902aca2111ad7e3e6186db907 Mon Sep 17 00:00:00 2001
From: Robin Lu <iamawalrus@gmail.com>
Date: Tue, 8 Jul 2008 16:06:33 +0800
Subject: [PATCH] fix build on mac os x
---
src/Makefile.am | 2 +-
src/network.c | 167 -----------------------------------------------
src/network_backends.c | 169 ++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 170 insertions(+), 168 deletions(-)