This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
Dir.chdir(File.expand_path("~/Library/Application\ Support/TextMate/Bundles/")) do | |
Dir.foreach(".") do |dir| | |
if File.directory?(dir) | |
Dir.chdir(dir) do | |
puts "Update Bundle #{File.basename Dir.getwd}" | |
puts %x{git pull} | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# analytics/app/support/report_invoker.rb | |
class ReportInvoker | |
def self.build_reports(dir) | |
new(dir).build_reports | |
end | |
attr_reader :dir | |
def initialize(dir) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NotesController < ApplicationController | |
def index | |
load_notes | |
end | |
def show | |
load_note | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def colorize(text, color_code) | |
"\e[#{color_code}m#{text}\e[0m" | |
end | |
def red(text); colorize(text, 31); end | |
def green(text); colorize(text, 32); end | |
def yellow(text); colorize(text, 33); end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'json' | |
#export | |
users = User.all.map {|user| {:id => user.id, :name => user.name }} | |
File.open("/tmp/users.json","w") do |f| | |
f.write(JSON.pretty_generate(users)) | |
end | |
#import |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'ohai' | |
ohai = Ohai::System.new | |
puts ohai.data.to_hash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'listen' #https://github.com/guard/listen | |
dir = "/Users/michaeldeimel/entwicklung/freeletics/core-user-rails" | |
listener = Listen.to(dir) do |modified, added, removed| | |
puts "modified absolute path: #{modified}" | |
puts "added absolute path: #{added}" | |
puts "removed absolute path: #{removed}" | |
end | |
listener.start # not blocking | |
sleep |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
message_verifier = Rails.application.message_verifier("some salt") | |
token = message_verifier.generate("my versecure thing") | |
message_verifier.verify(token) # => "my versecure thing" | |
# more params | |
token = message_verifier.generate([@user.id, email, "some message"]) | |
user_id, email, message = message_verifier.verify(token) # => "my versecure thing" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File.open("out.csv", 'w') { |f| f << Ranking.where(:client_instance_id => 14).map {|r| "#{r.id};\"#{r.supplier.name}\";\"#{r.comment}\" "}.join("\n") } |