Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View MBO's full-sized avatar

Mirosław Boruta MBO

  • Lędziny, Poland
View GitHub Profile
@MBO
MBO / 0_reuse_code.js
Created January 2, 2014 14:43
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
#!/usr/bin/env ruby
def flood(*heights)
stack = []
max = 0
volume = 0
heights.each do |height|
level = [max, height].min
count = 0
@MBO
MBO / proline.js
Created March 19, 2013 12:28
Userscript for Opera, to remove autofocus in http://proline.pl shop
if (location.hostname.indexOf('proline.pl') != -1) {
window.opera.addEventListener('BeforeScript', function(e) {
e.element.text = e.element.text.replace(/\.(focus\s*\(\))/g, "/* $1 -- commented by userscript */");
}, false);
}
@MBO
MBO / robot.js
Created December 5, 2012 10:39
mbo
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
@MBO
MBO / with_http_router.rb
Created November 28, 2012 21:43
Cramp example with Journey instead of HttpRouter
require "bundler"
Bundler.setup(:default)
require "cramp"
require "http_router"
require "thin"
class HomeController < Cramp::Action
def before_start
if params[:password] != "foo"
@MBO
MBO / README
Created June 1, 2011 11:38
How to convert params for nested attributes and _destroy
Convert params in form:
"product_suppliers_attributes"=>{
"0"=>{"id"=>"2", "_destroy"=>"false", "supplier_id"=>"1"},
"1"=>{"id"=>"3", "_destroy"=>"false", "supplier_id"=>"3"}
}
to form:
"product_suppliers_attributes"=>[
mirko@akagi.pts/7 ~/Code/rolldice
23:02:57 % ./rdp 1d6 2d6 3d6
1d6
1d6+0
min: 1, max: 6, avg: 3.5
| # | cnt | cumulative distribution | probability mass |
+===+=====+==========================================+==========================================+
| 1 | 1 | ###### | ###### |
| 2 | 1 | ############# | ###### |
| 3 | 1 | #################### | ###### |
namespace :delayed_job do
desc "*HACK* Restart the delayed_job process"
task :restart do
stop
enforce_stop_delayed_job
start
end
# Send SIGTERM to delayed_job associated with current logfile and then
# wait for every delayed_job to finish
This example shows how to setup an environment running Rails 3 beta under 1.9.1 with a 'rails3' gem set.
∴ rvm update --head
# ((Open a new shell)) or do 'rvm reload'
# If you do not already have the ruby interpreter installed, install it:
∴ rvm install 1.9.1
# Switch to 1.9.1 and gemset rails3, create if it doesn't exist.
∴ rvm --create use 1.9.1@rails3
/*
* How to build a Google Map and bind a SearchControl to it and put markers
* on the map for each result we receive.
*/
// First, we have to load the APIs.
google.load('maps' , '2');
google.load('search' , '1');
// Global variables we will set in OnLoad