Skip to content

Instantly share code, notes, and snippets.

View stereosupersonic's full-sized avatar

MICE Portal stereosupersonic

View GitHub Profile
@stereosupersonic
stereosupersonic / internet_connection.rb
Created May 3, 2012 08:32
check internet connenction
#from here: http://stackoverflow.com/questions/2385186/check-if-internet-connection-exists-with-ruby
require 'open-uri'
def internet_connection?
begin
true if open("http://www.google.com/")
rescue
false
end
require 'rubygems'
require 'ohai'
ohai = Ohai::System.new
puts ohai.data.to_hash
@stereosupersonic
stereosupersonic / export.rb
Created July 15, 2013 08:40
Export to csv
File.open("out.csv", 'w') { |f| f << Ranking.where(:client_instance_id => 14).map {|r| "#{r.id};\"#{r.supplier.name}\";\"#{r.comment}\" "}.join("\n") }

Capybara Cheat Sheet

Navigating

visit('/projects')
visit(post_comments_path(post))

Clicking Links and Buttons

SecureRandom.uuid
@stereosupersonic
stereosupersonic / Gemfile
Created February 23, 2014 19:12
Rails Testing Setup
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"
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
class NotesController < ApplicationController
def index
load_notes
end
def show
load_note
end
@stereosupersonic
stereosupersonic / parser.rb
Created September 26, 2014 06:33
rockantenne logger
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
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