Skip to content

Instantly share code, notes, and snippets.

View moretea's full-sized avatar

Maarten Hoogendoorn moretea

View GitHub Profile
class Result
include Mongoid::Document
include Mongoid::Timestamps
FIELD_NAMES = [:persoonlijk, :versie, :brainstorm, :brainstorm_time]
(1..80).each { |n| FIELD_NAMES << :"stroop_#{n}" }
(1..6).each { |n| FIELD_NAMES << :"tekst_check_q#{n}" }
(1..8).each { |n| FIELD_NAMES << :"likert-l#{n}" }
(1..9).each { |n| FIELD_NAMES << :"likert-exit_b#{n}" }
@moretea
moretea / gist:1026658
Created June 15, 2011 07:46
order_files
syslogs = [
"/path/to/log/apache.5.gz",
"/path/to/log/apache.1.gz",
"/path/to/log/apache.10.gz",
"/path/to/log/apache.256.gz"
]
output = syslogs.collect do |file_name|
file_name.match /(.*)\.(\d+)\.gz/
[$2.to_i, file_name]
maarten@web1:~/current$ sudo -u www-data GEM_HOME=/srv/rails/gems /srv/rails/nbb_production/app/current/script/delayed_job startsudo: sorry, you are not allowed to set the following environment variables: GEM_HOME
maarten@web1:~/current$ sudo -u www-data GEM_HOME=/srv/rails/gems /srv/rails/nbb_production/app/current/script/delayed_job start
sudo: sorry, you are not allowed to set the following environment variables: GEM_HOME
maarten@web1:~/current$ export GEM_HOME=/srv/rails/gems
maarten@web1:~/current$ sudo -u www-data /srv/rails/nbb_production/app/current/script/delayed_job start
/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- bundler/setup (LoadError)
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require'
from /srv/rails/nbb_production/app/current/script/delayed_job:4
@moretea
moretea / restart_wifi_if_no_network.rb
Created September 22, 2011 09:54
Restart the networking stack if the wifi connection has died
#!/usr/bin/env ruby
STDOUT.sync=true
CHECK_HOST = "google.nl"
def check_connection
system("ping #{CHECK_HOST} -c 5 1> /dev/null 2>/dev/null")
return true if $? == 0
end
@moretea
moretea / fast_helper.rb
Created October 10, 2011 00:00
Fast spec helper
# Include the lib path in the load path
lib = File.expand_path('../lib/', __FILE__)
$:.unshift lib unless $:.include?(lib)
require "fast_helper"
require "businessr/core/plugins"
require "businessr/plugins"
# => Both not needed because of the mocking of the plugin
#require "businessr/core/plugin"
#require "businessr/plugin"
describe BusinessR::Core::Plugins do
@moretea
moretea / gist:1274406
Created October 10, 2011 00:12
rspec output
$ time rspec spec/fast/core/plugins_spec.rb
..
Finished in 0.00052 seconds
2 examples, 0 failures
real 0m0.639s
user 0m0.460s
sys 0m0.130s
module Plugin::SupportTickets::UI
include BusinessR::UI
define :ui do
main_menu_item "Customer" do
menu_item "Support Tickets" do
on_click :open_view => "List"
menu_item "List all" { on_click :open_view => "List" }
menu_item "Search" { on_click :open_view => "Search" }
menu_item "New" { on_click :open_view => "New" }
module Plugin::SupportTickets::Models
include BusinessR::Base::Models
class Ticket < BaseModel
configure do
has :workflow
has :optimistic_locking
has :versions do |config|
config.included_relations = [:posts]
end
@moretea
moretea / gist:1279726
Created October 11, 2011 22:56
Run foreman
$ foreman start
00:55:15 web.1 | started with pid 24590
00:55:15 worker.1 | started with pid 24591
00:55:15 sphinx.1 | started with pid 24592
00:55:35 worker.1 | [Worker(host:maarten-samsung pid:24594)] Starting job worker
<more of this stuff>