Skip to content

Instantly share code, notes, and snippets.

@Deradon
Deradon / wtf.rb
Created November 7, 2012 20:24
wtf.rb
def rgb_to_hsv(r, g, b)
if r == b && r == g
h = s = 0
v = (0.299 * r + 0.587 * g + 0.114 * b) / 255
else
max = [r, g, b].max.to_f
min = [r, g, b].min.to_f
v = max
s = min
@Deradon
Deradon / live.rb
Last active December 16, 2016 14:36
Re-run a command whenever a file in directory is changed!
#!/usr/bin/env ruby
# Re-run a command whenever a file in directory is changed!
#
# Inspired by: http://ngauthier.com/2012/02/quick-tests-with-bash.html
# Thanks Nick!
#
# Patrick Helm (me@patrick-helm.de), 2013
#
#
@Deradon
Deradon / git_fix.rb
Last active September 12, 2016 21:55
Simple git-snippet to commit a small fix with auto-generated commit-message.
#!/usr/bin/env ruby
# Author: Patrick Helm (deradon87@gmail.com), 2013
#
#
# Simple git-snippet to commit a small fix with auto-generated commit-message.
#
# ## Description
#
# I noticed, we developers often needs to fix a small typo or do something
@Deradon
Deradon / touchpad-disable.rb
Created February 8, 2013 00:29
HP-Notebook - Disable/Enable touchpad on command-line
#!/usr/bin/env ruby
# Simple script to disable TouchPad on HP-Notebook
#
# Usage: touchpad-disable
#
# Installation: save file to ~/bin/touchpad-disable (may chmod +X it)
#
def run(cmd, options = {:show => true})
puts "> #{cmd}"
@Deradon
Deradon / engine_gemspec.rb
Created February 20, 2013 22:01
Sample gemspec for Rails::Engine
$:.push File.expand_path("../lib", __FILE__)
# Maintain your gem's version:
require "cmf_raffle_widget/version"
# Describe your gem and declare its dependencies:
Gem::Specification.new do |s|
s.name = "cmf_raffle_widget"
s.version = CmfRaffleWidget::VERSION
s.authors = ["Patrick Helm"]
@Deradon
Deradon / Rakefile
Created February 20, 2013 22:05
Samle Rails::Engine Rakefile
#!/usr/bin/env rake
begin
require 'bundler/setup'
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end
begin
require 'rdoc/task'
rescue LoadError
require 'rdoc/rdoc'
@Deradon
Deradon / spec_helper.rb
Created February 20, 2013 22:06
Sample Rails::Engine spec_helper.rb
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../spec/dummy/config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'active_scaffold'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
@Deradon
Deradon / hmb8.rb
Created June 5, 2013 19:36
Humble Indie Bundle 8 - Stats
# Patrick Helm - @htwk_pat - 2013
#
# Humblde Bundle 8 - 05.06.2013
#
# Stats - Estimate purchases per plattform
total_payments = 2174259.44
purchases = 378038
average_purchase = 5.75
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.de"><img alt="Creative Commons Lizenzvertrag" style="border-width:0" src="http://i.creativecommons.org/l/by-nc-sa/3.0/80x15.png" /></a>
@Deradon
Deradon / flowdock.rb
Created November 9, 2015 14:30
flowdock
class WimduFlowdockPullRequestService
TOKEN = Rails.application.secrets.flowdock_api_token
FLOW_ID = Rails.application.secrets.flowdock_flow_id
OCTOCAT = ":octocat:"
def self.run(*args)
new(*args).run
end
def initialize(event)