Skip to content

Instantly share code, notes, and snippets.

View henrik's full-sized avatar

Henrik Nyh henrik

View GitHub Profile
@henrik
henrik / update_loopia_dyndns.rb
Created January 16, 2009 10:17
Ruby script to update dynamic DNS on Swedish LoopiaDNS.
#!/usr/bin/env ruby
# Updates dynamic DNS on Swedish LoopiaDNS.
# Run in crontab, e.g.:
# */15 * * * * ruby /usr/local/bin/update_loopia_dyndns.rb
USERNAME = "foo.com"
PASSWORD = "bar"
DOMAINS = %w[
foo.com
@henrik
henrik / personnummer.rb
Created January 29, 2009 11:53
Generate valid Swedish personnummer.
# Generator for valid Swedish personnummer: http://en.wikipedia.org/wiki/Personal_identity_number_(Sweden)
# By Henrik Nyh <http://henrik.nyh.se> 2009-01-29 under the MIT license.
require 'date'
module Personnummer
def self.generate(date=nil, serial=nil)
date ||= Date.new(1900+rand(100), 1+rand(12), 1+rand(28))
serial = serial ? serial.to_s : format("%03d", 1+rand(999)) # 001-999
@henrik
henrik / README.markdown
Created February 6, 2009 21:49
Stitch Zoomify tiles into a single image (Ruby + ImageMagick).
@henrik
henrik / hexcolor.rb
Created February 10, 2009 10:08
Calculate opacity for hexadecimal colors in Ruby.
#!/usr/bin/env ruby
#
# Calculate opacity for hexadecimal colors.
# By Henrik Nyh <http://henrik.nyh.se> 2009-02-10 under the MIT License.
module Hexcolor
extend self
def opacity(fg, opa=1.0, bg='FFFFFF')
raise "Opacity must be between 0 and 1.0, but was #{opa}" unless (0..1.0).include?(opa)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>name.henriknyh.znc</string>
<key>Program</key>
<string>/usr/local/bin/znc</string>
<key>RunAtLoad</key>
<true/>
@henrik
henrik / logrotate.conf
Created February 21, 2009 14:27
Passenger+Rails/Merb logrotate example config.
# Install logrotate on OS X:
# sudo port clean --all logrotate && sudo port install logrotate
# Add e.g. this to your crontab:
# /opt/local/sbin/logrotate -s /Users/deploy/.logrotate/sites.status /Users/deploy/.logrotate/sites.conf
# This file would be sites.conf.
# See http://overstimulate.com/articles/logrotate-rails-passenger for more info.
daily
missingok
rotate 30
@henrik
henrik / jquery.checkboxes.js
Last active October 24, 2017 12:01
jQuery checkbox utilities: check range, master toggle box, check/uncheck all.
// jQuery checkbox utility plugin.
// Triggers "change" events on the checkboxes.
// By Henrik Nyh <http://henrik.nyh.se> 2009-04-27 under the MIT License.
(function($) {
function makeChecked($checkboxes, checked) {
return $checkboxes.prop("checked", checked).trigger("change");
}
@henrik
henrik / application_mailer.rb
Created March 6, 2009 13:04
Cancel mail from within an ActionMailer deliver_* method.
# Allow cancelling mails from within an ActionMailer deliver_* method by doing "raise NotSendingMail".
# In an ApplicationMailer that other mailers inherit from:
class NotSendingMail < StandardError; end
def self.method_missing(*args)
super
rescue NotSendingMail => e
Rails.logger.info("Not mailing! #{e}")
end
@henrik
henrik / get_analytics_visitors.rb
Created March 12, 2009 16:33
Ruby+Google::Base to get "absolute unique visitors" for a given date range from Google Analytics.
# Get "absolute unique visitors" for a given date range from Google Analytics.
# By Henrik Nyh <http://henrik.nyh.se> 2009-03-12. Public domain.
require 'rubygems'
require 'google/base' # sudo gem install googlebase
require 'date'
FROM = Date.today - 10
UNTO = Date.today
SITE_ID = '12345678'
@henrik
henrik / rails_template.rb
Created March 29, 2009 08:59
Rails template for Rails 2.3. Work in progress.
# Rails template for Rails 2.3. Work in progress.
# By Henrik Nyh (http://henrik.nyh.se) 2009-03-29. Public domain.
# Usage: rails myapp -m http://gist.github.com/87341.txt
META_AUTHOR = "Henrik Nyh (http://henrik.nyh.se)"
JQUERY_VERSION = "1.3.2"
APP_NAME = File.basename(Dir.pwd)
git :init