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
@pzi
pzi / input_file.css
Created February 20, 2013 06:34
Style input type="file" in Webkit (Chrome, Safari)
input[type=file] {
position: relative;
-webkit-appearance: textfield;
-webkit-box-sizing: border-box;
}
input[type=file]::-webkit-file-upload-button {
border: none;
margin: 0;
padding: 0;
@pzi
pzi / custom_select.coffee
Last active December 14, 2015 07:49
This script provides a workaround to apply custom style to a SELECT element. It dynamically wraps the targeted SELECT in a DIV and adds a SPAN element positioned absolutely after/below the SELECT element. This SPAN element then gets the selected option text. The SELECT will get opacity set to zero, so it is not visible but clickable. Since the S…
$.fn.customSelect = ->
$(this).filter('select').each (i) ->
$select = $(this)
# make sure we only apply once, no matter how many times called with the same selector
return if $select.data('customSelect')
$select.data('customSelect', true)
title = $select.find('option:first').text()
@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)

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

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
@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)
@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 / 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 / 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

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: