Skip to content

Instantly share code, notes, and snippets.

🦆
🦆 🦆 🦆 🦆

Henrik Nyh henrik

🦆
🦆 🦆 🦆 🦆
Block or report user

Report or block henrik

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
View eyetv_xmltv_grabber.rb
#!/usr/bin/env ruby
# SweDB XMLTV Grabber for EyeTV
# by Henrik Nyh <http://henrik.nyh.se> under the MIT License.
#
# INSTALLATION
#
# Configure the list of channels below and run this script as a cron job, e.g.
#
# 0 */12 * * * ruby /path/to/this/script.rb
View gist:27428
require 'net/http'
require 'digest/md5'
# Is there a Gravatar for this email?
def gravatar?(email)
hash = Digest::MD5.hexdigest(email.to_s.downcase)
response = Net::HTTP.new('www.gravatar.com', 80).request_head("/avatar/#{hash}?size=1&default=.")
response.code != '302'
end
@henrik
henrik / Ensure Image Extension.scpt
Created Nov 21, 2008
Fix missing/incorrect image file extension on download. See http://henrik.nyh.se/2008/11/extension-action for details.
View Ensure Image Extension.scpt
on adding folder items to myFolder after receiving myFiles
repeat with myFile in myFiles
set myPath to (POSIX path of myFile)
set myType to do shell script "file --mime-type -br " & (quoted form of myPath)
if myType is "image/jpeg" and myPath does not end with ".jpg" and myPath does not end with ".jpeg" then
set newExtension to ".jpg"
else if myType is "image/gif" and myPath does not end with ".gif" then
set newExtension to ".gif"
@henrik
henrik / unsimple_format.rb
Created Nov 28, 2008
Like Rails' simple_format but avoids <p>/<br /> around some block tags.
View unsimple_format.rb
# From Rails
def simple_format(text, html_options={})
start_tag = '<p>'
text = text.to_s.dup
text.gsub!(/\r\n?/, "\n") # \r\n and \r -> \n
text.gsub!(/\n\n+/, "</p>\n\n#{start_tag}") # 2+ newline -> paragraph
text.gsub!(/([^\n]\n)(?=[^\n])/, '\1<br />') # 1 newline -> br
text.insert 0, start_tag
text << "</p>"
end
@henrik
henrik / init.rb
Created Nov 28, 2008
Simple Settings object for Merb.
View init.rb
Merb::BootLoader.before_app_loads do
# This will get executed after dependencies have been loaded but before your app's classes have loaded.
require 'config/settings'
end
@henrik
henrik / .bashrc
Created Dec 3, 2008
Git branch and dirty state in Bash prompt.
View .bashrc
# http://henrik.nyh.se/2008/12/git-dirty-prompt
# http://www.simplisticcomplexity.com/2008/03/13/show-your-git-branch-name-in-your-prompt/
# username@Machine ~/dev/dir[master]$ # clean working directory
# username@Machine ~/dev/dir[master*]$ # dirty working directory
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"
@henrik
henrik / rails_ext.rb
Created Dec 5, 2008
Make Rails' parameterize remove apostrophes.
View rails_ext.rb
module ActiveSupport::Inflector
# Parameterize "Foo's and Charles's bar" into "foos-and-charles-bar"
# instead of into "foo-s-and-charles-s-bar".
def parameterize_with_apostrophe_removal(string, sep = '-')
string = string.dup
string.gsub!(%r{s's\b}i, 's')
string.gsub!(%{'}, "")
parameterize_without_apostrophe_removal(string, sep)
end
View back.sh
#!/bin/bash
ssh hyper "osascript -e 'tell app \"iTunes\" to back track'"
View .irbrc
# http://pablotron.org/software/wirble/
# Provides "ri", history survives restart etc
require 'rubygems'
require 'wirble'
Wirble.init
# http://www.quotedprintable.com/2007/9/13/my-irbrc
# Show rails root in script/console prompt
require 'irb/completion'
View httpd-vhosts.conf
# Make Apache with enabled mod_proxy forward http://ak.dev/foo
# to http://ak.dev:3000/foo for use in local Rails development.
<VirtualHost *:80>
ServerName ak.dev
RewriteEngine on
RewriteRule /(.*) http://localhost:3000/$1 [P]
</VirtualHost>
You can’t perform that action at this time.