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 / context.tsx
Created April 12, 2022 07:27 — forked from JLarky/README.md
Ultimate example of react context hook with nice type-safe (TypeScript) wrappers and reduced boilerplate by using `ReturnType`
import React from "react";
import { useImmer } from "use-immer";
function useProviderValue() {
const [moved, setMoved] = React.useState(false);
const [point, setPoint] = useImmer<{
x: number;
y: number;
}>({ x: 0, y: 0 }); // using immer to illustrate that you can easily derive setPoint type instead of writing types for Context manually
const value = React.useMemo(
#= 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(', ')
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