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 / conditional_types.tsx
Last active July 23, 2019 03:30
TypeScript: Conditional types and discriminated unions & narrowing
type Block = Important | Emphasis | Regular
type BK = Block['kind']
type Important = { kind: 'important'; important: string }
type Emphasis = { kind: 'emphasis'; emphasis: string }
type Regular = { kind: 'text'; text: string }
type SmartOpts<T extends Block['kind']> = Extract<Block, { kind: T }>
type RegularOptions = SmartOpts<'text'>
@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
@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 / .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 / 01_introduction.js
Created January 14, 2017 15:50
my learnyounode solutions
console.log('HELLO WORLD');
@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 / 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 / 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 / SassMeister-input-HTML.jade
Last active August 29, 2015 14:21
Generated by SassMeister.com.
.something
.selector
.svg
.selector
.backgroundsize
.selector
.svg.backgroundsize
#= 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'