Skip to content

Instantly share code, notes, and snippets.

@polarblau
polarblau / de.yml
Created October 23, 2012 08:22 — forked from newstler/de.yml
#iOSonRailsConf 2013 web site translations
##############################
##############################
robot_in_the_cloak: "Robot in the Cloak"
site_title: "#iOSonRailsConf 2013"
site_description: "Eine Konferenz für Ruby on Rails und iOS-Entwickler aus aller Welt, die im Frühjahr 2013 in Aluschta stattfinden wird."
site_description_short: "Ruby on Rails und iOS-Entwickler Konferenz."
site_keywords: "Ruby, Rails, ios, Entwickler, Konferenz, 2013, Web, Handy, iphone, ipad, ipod"
@polarblau
polarblau / color_helpers.rb
Created November 3, 2012 21:30
Ruby color helpers
# http://24ways.org/2010/calculating-color-contrast
def contrast_color(hex_color, dark_option, bright_option)
rgb = hex_to_rgb(hex_color)
yiq = luminance(*rgb) / 1000
yiq >= 128 ? dark_option : bright_option
end
def hex_to_rgb(hex_color)
hex_color = hex_color.gsub(%r{[#;]}, '')
case hex_color.size
@polarblau
polarblau / .bash
Last active October 13, 2015 03:58
Plain html file for quick local JS experiments
function html() {
curl -o ${1-index.html} https://gist.github.com/polarblau/4135905/raw/361a71ab43012ab149744fa4bd4a0e837d0a0200/index.html
}
// ...
$color-variation: 10%
$color-set-1: $dark-violet $dark-green $orange
$color-set-2: $gray $bright-violet $bright-green
$color-set-3: $turquoise $yellow $red
$color-sets: $color-set-1 $color-set-2 $color-set-3
=color($property: color, $level: 1, $variation: 0)
# http://bateru.com/news/2011/03/javascript-standard-deviation-variance-average-functions/
getNumWithSetDec = (num, numOfDec = 3) ->
pow10s = Math.pow(10, numOfDec)
(if (numOfDec) then Math.round(pow10s * num) / pow10s else num)
getAverageFromNumArr = (numArr, numOfDec) ->
return false unless _.isArray(numArr)
i = numArr.length
sum = 0
sum += numArr[i] while i--
@polarblau
polarblau / template.php.haml
Created January 13, 2013 20:28
meta_wordpress example
:docs
Template Name: Home
- content_for :page_lift do
= partial "home_lift"
%article
.content-wrapper
= php "if (have_posts()):" do
= php "while (have_posts()): the_post()" do
@polarblau
polarblau / jquery.baseplugin.coffee
Created February 11, 2013 13:08
Base for new jQuery plugins written in Coffeescript. Enables plugin methods. Based on http://coffeescriptcookbook.com/chapters/jquery/plugin and http://docs.jquery.com/Plugins/Authoring#Plugin_Methods .
$ = jQuery
$.fn.extend
foobar: (method) ->
settings =
option1: true
option2: false
class Hash
def merge_html_attr!(other)
merged = self.merge(other) do |key, a, b|
if key == :class && a.is_a?(String) && b.is_a?(String)
[a, b].join(' ')
else
b
end
end
@polarblau
polarblau / gist:5186457
Last active December 15, 2015 02:19
Sonera (Finland) Invoice Bookmarklet. Will open only the invoice (without iframe) and trigger the printing dialog.
javascript:(function(e,a,g,h,f,c,b,d)%7Bif(!(f%3De.jQuery)%7C%7Cg%3Ef.fn.jquery%7C%7Ch(f))%7Bc%3Da.createElement(%22script%22)%3Bc.type%3D%22text/javascript%22%3Bc.src%3D%22//ajax.googleapis.com/ajax/libs/jquery/%22%2Bg%2B%22/jquery.min.js%22%3Bc.onload%3Dc.onreadystatechange%3Dfunction()%7Bif(!b%26%26(!(d%3Dthis.readyState)%7C%7Cd%3D%3D%22loaded%22%7C%7Cd%3D%3D%22complete%22))%7Bh((f%3De.jQuery).noConflict(1),b%3D1)%3Bf(c).remove()%7D%7D%3Ba.documentElement.childNodes%5B0%5D.appendChild(c)%7D%7D)(window,document,%221.8.0%22,function(%24,L)%7Bvar%20loc%3D%24(%22iframe.iFrameStyle%22).attr(%22src%22)%3Bvar%20win%3Dwindow.open(loc)%3Bwin.print()%3B%7D)%3B
@polarblau
polarblau / crawler_api.rb
Created March 18, 2013 11:14
Simple crawler API
options = { :wait => 10 }
# one big set
result = Crawler.crawl("http://www.example.com", options)
result.image
result.style_sheets
result.scripts # => [<Crawler::Response::Script>]
...
result.errors