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 / 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(', ')
#= 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 / SassMeister-input-HTML.jade
Last active August 29, 2015 14:21
Generated by SassMeister.com.
.something
.selector
.svg
.selector
.backgroundsize
.selector
.svg.backgroundsize
@pzi
pzi / scales.js
Created September 22, 2015 01:39
// this = marker under mouse
const matrix = this.getScreenCTM()
.translate(+this.getAttribute('cx'), +this.getAttribute('cy'));
const graphDiv = document.getElementById(graphOptions.chart.id).getBoundingClientRect();
let tooltTipLeftpx = matrix.e - graphDiv.left;
if (tooltTipLeftpx > (graphOptions.chart.width - (graphOptions.chart.padding * 1.5))) {
tooltTipLeftpx -= graphOptions.chart.padding * 2;
@pzi
pzi / cycle2.html.haml
Created April 29, 2016 07:28
Use cycle2 with progressive loading in Haml
.cycle-slideshow.auto{data: { cycle_loader: true, cycle_progressive: "#slideshow-images" }}
-# default image loaded
= image_tag "image0.jpg", alt: ""
%script#slideshow-images{type: "text/cycle"}
- image_count = 6
[
- (1..image_count).each_with_index do |i|
- path = image_path("image#{i}.jpg")
@pzi
pzi / menu.coffee
Created July 6, 2016 07:51
Dropdown submenu
$ ->
closeTimeout = 200
isSubmenuOpen = false
toggleSubmenu = (event, $li) ->
$target = $(event.target)
event.preventDefault()
if isSubmenuOpen
closeSubmenu($li)
else
@pzi
pzi / 01_introduction.js
Created January 14, 2017 15:50
my learnyounode solutions
console.log('HELLO WORLD');
@pzi
pzi / .bash_profile
Last active April 27, 2017 09:30
Gets JIRA card number from git branch name and inserts it into the commit message.
function get-jira-card-number {
# Assuming branch names have the following body: XX-1234-Title,
# we are only interested in XX-1234.
git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3-8 | cut -d"-" -f 1-2
}
function jira-card-number-commit {
local number=`get-jira-card-number`
local message=$1;
@pzi
pzi / .hyper.js
Created September 6, 2017 08:45
Hyper config
module.exports = {
config: {
// default font size in pixels for all tabs
fontSize: 14,
// font family with optional fallbacks
fontFamily: 'Menlo, "DejaVu Sans Mono", Consolas, "Lucida Console", monospace',
// terminal cursor background color and opacity (hex, rgb, hsl, hsv, hwb or cmyk)
cursorColor: 'rgba(248,248,248,0.8)',
@pzi
pzi / pre-commit-tslint
Last active May 13, 2019 06:33
Pre Commit hook to run TSLint before committing. Based off https://gist.github.com/rashtay/328da46a99a9d7c746636df1cf769675 ---- add to `.git/hooks/` as `pre-commit` and run `chmod +x .git/hooks/pre-commit`.
#!/bin/sh
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep ".[j|t]sx\{0,1\}$")
TSLINT="$(git rev-parse --show-toplevel)/WebClient/node_modules/.bin/tslint"
if [[ "$STAGED_FILES" = "" ]]; then
exit 0
fi
PASS=true