Skip to content

Instantly share code, notes, and snippets.

View pzi's full-sized avatar
🇨🇭
Grüessech

Patrik Affentranger pzi

🇨🇭
Grüessech
View GitHub Profile
#= require jquery
#= require jquery-sort
$locationsContainer = $('#locations')
locationsData = $locationsContainer.data('locations')
currentCoords = latitude: 0, longitude: 0
locations = []
firstRun = true
if typeof (Number::toRad) is 'undefined'
@pzi
pzi / image_set_tag_helper.rb
Last active August 30, 2018 19:49 — forked from youngbrioche/images_helper.rb
Middleman helper that acts as thin wrapper for the image_tag helper. It generates the srcset attribute for regular image tags.
helpers do
# Acts as a thin wrapper for image_tag and generates a srcset attribute for regular image tags
# for usage with responsive images, supports middleman's asset_path helper.
#
# image_set_tag 'pic_1980.jpg', { 'pic_640.jpg' => '640w', 'pic_1024.jpg' => '1024w', 'pic_1980.jpg' => '1980w' }, sizes: '100vw', class: 'my-image'
#
# => <img src="/assets/ants_1980.jpg" srcset="/assets/pic_640.jpg 640w, /assets/pic_1024.jpg 1024w, /assets/pic_1980.jpg 1980w" sizes="100vw" class="my-image">
#
def image_set_tag(source, srcset = {}, options = {})
srcset = srcset.map { |src, size| "#{asset_path(:images, src)} #{size}" }.join(', ')

Keybase proof

I hereby claim:

  • I am pzi on github.
  • I am pzi (https://keybase.io/pzi) on keybase.
  • I have a public key whose fingerprint is FF3F 1C96 C62C 6000 5271 96A6 E99A 9CE4 AB53 A92F

To claim this, I am signing this object:

@pzi
pzi / config.rb
Created May 30, 2014 03:24
Active page checker for navigation elements within middleman app
helpers do
def nav_active(url)
if (url.instance_of? String)
current_resource.url == url_for(url) ? {class: "active"} : {}
elsif (url.instance_of? Array)
url.map { |url| url_for(url) }.include?(current_resource.url) ? {class: "active"} : {}
else
{}
end
end
@pzi
pzi / latest-tweet.coffee
Last active August 29, 2015 14:01
Display and store (sessionStorage) the latest tweet without having to use Twitter OAuth.
# How to create a valid ID to use
# 1. Go to www.twitter.com and sign in as normal, go to your settings page.
# 2. Go to "Widgets" on the left hand side.
# 3. Create a new widget for what you need eg "user timeline" or "search" etc.
# 4. Feel free to check "exclude replies" if you dont want replies in results.
# 5. Now go back to settings page, and then go back to widgets page, you should
# see the widget you just created. Click edit.
# 6. Now look at the URL in your web browser, you will see a long number like this:
# 345735903485048478
# 7. Use this as your WIDGET_ID below instead!
@pzi
pzi / GravityForms-FieldValidation.php
Last active August 29, 2015 13:57
Gravity Forms additions
<?php
// This file would be inside functions.php or a custom filter plugin that get's imported into functions.php
// Added custom validation for minimum character count of a textfield
// 4 refers to the form id
// 6 refers to the field id in that form
// 10 refers to priority the filter has (WP related)
// 4 again is an additional parameter for gform, in this case, the id of the form the target field belongs to
add_filter("gform_field_validation_4_6", "validate_input_length", 10, 4);
@pzi
pzi / compass-spriting.sass
Created October 16, 2013 13:43
How to get each icon dimension when using compass sprites.
$test_icons-sprite-map: sprite-map("some-icons/*.png")
$test_icons-sprite-names: sprite-names($test_icons-sprite-map)
@each $name in $test_icons-sprite-names
.some-icon-#{$name}
@include sprite-dimensions($test_icons-sprite-map, $name)
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://npmjs.org/install.sh | sh

Using Yeoman and Jade

Getting started

  • Make sure you have yo installed: npm install -g yo
  • Run: yo webapp
  • Install grunt-contrib-jade: npm install grunt-contrib-jade --save-dev

Customization

@pzi
pzi / download.html.haml
Created March 26, 2013 08:53
Force download files in Ruby on Rails
= link_to 'Download 1', download_path(:symbol1_name)
= link_to 'Download 2', download_path(:symbol2_name)