Skip to content

Instantly share code, notes, and snippets.

View henrik's full-sized avatar

Henrik Nyh henrik

View GitHub Profile
@henrik
henrik / Plex Toggle.scpt
Created November 21, 2009 23:28
Start Plex if not running. Make fullscreen if running windowed. Quit if running fullscreen.
-- Start Plex if not running. Make fullscreen if running windowed. Quit if running fullscreen.
-- By Henrik Nyh <http://henrik.nyh.se> 2009-11-22 under the MIT License.
-- Some code from http://forums.plexapp.com/index.php?/topic/8325-applescript-focusfullscreen-plex/
tell application "Plex"
-- "if it is running" is probably Snow Leopard only.
if it is running then
tell application "System Events" to tell process "Plex"
set isFullscreen to position of window 1 is {0, 0}
@henrik
henrik / aardvark.markdown
Created November 27, 2009 18:41
prawn/prawn-js code to autoprint a PDF document in Acrobat Reader.

Now a gem!

@henrik
henrik / yahoo_exchange_rates_jsonp.html
Created December 28, 2009 22:48
JavaScript to get currency exchange rates from Yahoo Finance as JSONP. No XHR!
Get exchange rate as JSONP via YQL.
YQL Console: http://developer.yahoo.com/yql/console
Query (USD to SEK): select rate,name from csv where url='http://download.finance.yahoo.com/d/quotes?s=USDSEK%3DX&f=l1n' and columns='rate,name'
Example code:
<script type="text/javascript">
@henrik
henrik / edit_chrome_extension_bookmarklet.js
Created December 29, 2009 11:05
Bookmarklet to go from public Chrome Extension page to edit page (if you wrote it). Can't be an extension/userscript since they're blocked on that site.
javascript:location.pathname=location.pathname.replace(/\/detail\/(\w+).*/, '/developer/edit/$1');
@henrik
henrik / google_reader_less_chrome.userstyle.css
Created January 9, 2010 23:39
Userstyle for Google Reader in Fluid.app. Gives the content more space.
/*
Fluid.app URL Pattern: http://www.google.tld/reader/*
*/
#gbar, .gbh, #viewer-footer { display: none !important; }
#global-info { top: 3px !important; right: 180px !important; z-index: 999; opacity: 0.1 }
#global-info:hover { opacity: 1 }
#global-info a { text-decoration: none }
@henrik
henrik / en.yml
Created January 13, 2010 13:42
Ruby on Rails i18n: storing locale names in their yml files and retrieving them.
# config/locales/en.yml
en:
i18n:
language:
name: 'English'
@henrik
henrik / monkeypatches.rb
Created January 14, 2010 13:01
Monkeypatch version of a patch by John Trupiano to fix a Rails bug with :include and symbol keys on :conditions.
# config/initializers/monkeypatches.rb
# Work around a Rails bug where e.g. :include => :foo, :conditions => { :'foo.bar' => 'baz' }
# would not include 'foo' unless 'foo.bar' is a string.
# https://rails.lighthouseapp.com/projects/8994/tickets/2998-named_scope-ignores-include-option
module ActiveRecord::Associations::ClassMethods
def tables_in_hash(hash)
return [] if hash.blank?

SHRUG: snabbhack: Blocket.se-scraper

Skrapa föremålsinformation från sökresultat på http://www.blocket.se. Parsa ofullständiga datumtider.

Uppgift

Filen imac.html är resultatet av en sökning på "imac" i Stockholm utförd 2010-01-27.

Skriv kod för att extrahera föremålsdata till en nästlad array. Tiden bör vara en Time, rubriken en String i UTF8 och priset en Integer.

@henrik
henrik / yamlator.rb
Created February 3, 2010 12:54
Helps you update Rails i18n YAML files programmatically.
# YAMLator by Henrik Nyh <http://henrik.nyh.se> 2010-02-03 under the MIT license.
# Helps you update Rails i18n YAML files programmatically, to be used e.g. for
# editor extraction tools.
$KCODE = 'u'
require "yaml"
require "rubygems"
require "ya2yaml" # Dumps with unescaped UTF-8.
@henrik
henrik / i18n.rb
Created February 4, 2010 13:25
Globalize1 view translation compatibility layer for Rails i18n.
# config/initializers/i18n.rb
# Globalize 1 compatibility. To be refactored away.
class GlobalizeTranslation < ActiveRecord::Base; end
class Globalize::ViewTranslation < GlobalizeTranslation; end
LANGUAGE_ID_EN = 1819
class String