Skip to content

Instantly share code, notes, and snippets.

🐢
I may be slow to respond.

MICE Portal stereosupersonic

🐢
I may be slow to respond.
Block or report user

Report or block stereosupersonic

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@stereosupersonic
stereosupersonic / Gemfile
Created Feb 23, 2014
Rails Testing Setup
View Gemfile
group :development do
gem 'guard-rspec', '~> 3.0.2'
gem 'guard-spork', '~> 1.5.1'
gem 'spork-rails', github: 'sporkrb/spork-rails'
gem 'rb-fsevent', '~> 0.9.3'
end
group :development, :test do
gem "rspec-rails", "~> 2.14.0"
gem "factory_girl_rails", "~> 4.2.1"
View export_to_excel.rb
data = Service.available_for(shop).map do |service|
[service.name_de, service.id, service.category, service.service_type, (service.global ? 'Ja': 'Nein')]
end
require 'spreadsheet'
def to_excel(data,filename = 'out.xls')
Spreadsheet.client_encoding = 'UTF-8'
book = Spreadsheet::Workbook.new
sheet = book.create_worksheet :name => filename
View tmux-cheatsheet.markdown

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
View notes_controller.rb
class NotesController < ApplicationController
def index
load_notes
end
def show
load_note
end
View parser.rb
def parse_rockantenne
url = 'http://www.webradio.de/webradio/titleinfos/rockantenne_rahome2.php'
doc= open(url).read
matched = doc.match(/<b>Aktueller Titel:<\/b><br>(.*)<br>(.*?)<\/div>/)
puts "#{matched[1]}-#{matched[2]}"
end
View system_bang.rb
def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==")
end
# for bin/setup
# system! 'gem install bundler --conservative'
# https://github.com/rails/rails/pull/20926/files
View show_constants.rb
Module.constants.select do |constant_name|
constant = eval constant_name
if not constant.nil?
puts "#{constant_name} : #{constant}"
end
end
View gist:119540
def self.timeout_guard(sec)
main = Thread.current
timer = Thread.new { sleep sec; main.raise "Timeout after #{sec} seconds" }
begin
yield
ensure
timer.kill
end
end
# use timeout_guard(10) {do_somthing }
View logger.rb
def logger
@logger ||= Logger.new(STDOUT, Logger::WARN)
end
#siehe http://blog.hasmanythrough.com/2009/12/15/no-returns
def logger
RAILS_DEFAULT_LOGGER
end
View my_template.rb
#template
#Constants
app_name = `pwd`.split('/').last.strip
rails_version = '2.3.2'
jquery_version = '1.3.2'
##### remove files #################
run "rm README"
run "rm -rf test"
You can’t perform that action at this time.