Skip to content

Instantly share code, notes, and snippets.

View astropanic's full-sized avatar

Wojciech Pietrzak astropanic

View GitHub Profile
@astropanic
astropanic / bb-code.rb
Created July 23, 2011 16:24
Extend bb-ruby to understand the [ruby]...[/ruby] tag
#config/initializers/bb-code.rb
module BBRuby
@@tags["Ruby"] = [
/\[ruby\](.*?)\[\/ruby\]/mi,
'<pre class="syntax ruby">\1</pre>',
'Ruby code',
'[ruby]User.last.inspect[/ruby]',
:ruby]
end
@astropanic
astropanic / gist:4f583740f93465fbd2bc
Created November 3, 2014 10:14
Ruby is a beautiful language
return (1<<31) - (name.downcase.each_byte.each_with_index.to_a.inject(0.0) {|s,(v,i)| s+=(v.to_f/[((2**8)*i), 1.0].max);s} * (2**23)).to_i

Keybase proof

I hereby claim:

  • I am astropanic on github.
  • I am astropanic (https://keybase.io/astropanic) on keybase.
  • I have a public key ASALn0AmyftU0jyEIviHRBE9txPGIjyWBNA5QPZ9vqpWyQo

To claim this, I am signing this object:

class Foo
def self.with_context
old = self.context #save current context
yield
@@context = old #return context back after method was run
end
def self.context=(value)
@@context = value
end
@astropanic
astropanic / console.js
Last active December 12, 2015 00:39
An example of the MongoDB aggregation framework
use wlw;
db.wlw.drop();
heading1 = { _id: 10001, name: "Schrauben" , company_counts: { "de":0, "at":9 }, keywords: ["Metall", "Gewinde", "Konstruktion"] };
heading2 = { _id: 10002, name: "Rohre" , company_counts: { "de":1, "at":3 }, keywords: ["Metall", "Profil" , "Konstruktion"] };
heading3 = { _id: 10003, name: "Holzballen", company_counts: { "de":3, "at":0 }, keywords: ["Holz" , "Bau" , "Konstruktion"] };
db.wlw.insert(heading1);
db.wlw.insert(heading2);
ruby x.rb
{"title":"SHINY NEW TITLE","bar":"blah"}
/*!
* jQuery outside events - v1.1 - 3/16/2010
* http://benalman.com/projects/jquery-outside-events-plugin/
*
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
// Script: jQuery outside events
@astropanic
astropanic / gist:1519209
Created December 25, 2011 12:53
gem install ray
Building native extensions. This could take a while...
ERROR: Error installing ray:
ERROR: Failed to build gem native extension.
/home/wojciech/.rvm/rubies/ruby-1.9.2-p290/bin/ruby extconf.rb
checking for GL/glxext.h... yes
checking for X11/extensions/Xrandr.h... yes
checking for main() in -lXrandr... yes
checking for main() in -lX11... yes
checking for main() in -lGL... yes
admin.qype.br
admin.qype.co.uk
admin.qype.com
admin.qype.es
admin.qype.fr
admin.qype.it
admin.qype.nl
admin.qype.pl
admin.qype.pt
bbc.qype.br
def test_including_modules_for_correct_country
Schober::Reader.expects(:send).with(:include, Schober::Mapping::Categories::Ch)
Schober::Reader.expects(:send).with(:include, Schober::Mapping::Columns::Ch)
Schober::Reader.expects(:send).with(:include, Schober::Computing::Ch)
Schober::Reader.new("ch")
end