Skip to content

Instantly share code, notes, and snippets.

View zwacky's full-sized avatar

Simon zwacky

View GitHub Profile
@zwacky
zwacky / isoCurrency.filter.js
Created November 25, 2014 14:53
isoCurrency Filter
angular.module('app')
.filter('isoCurrency', function($filter) {
var currencies = {
"ALL":{"text":"Lek"},
"AFN":{"text":"؋"},
"ARS":{"text":"$"},
"AWG":{"text":"ƒ"},
"AUD":{"text":"$"},
"AZN":{"text":"ман"},
@zwacky
zwacky / spread-example.js
Last active January 20, 2016 15:13
ES6 spread to the rescue
// get all items of all players
/* WITHOUT ES6 spread operator */
const items = [];
players.forEach((player) => {
player.forEach((item) => {
items.push(item);
});
});
/**
* e.g. retrieving field values from a form.
*/
function getDateFromForm() {
const props = ['year', 'month', 'day', 'hour', 'minutes', 'sec', 'milisec'];
return props.map((prop) => {
return document.querySelector(`#${prop}`).text;
});
}
@zwacky
zwacky / Nice Fonts
Created October 7, 2016 13:11
Nice fonts I came across the last years
- QuicksandBook
- QuicksandLight
- BLOKK
- Lobster
- DroidSerif
- PT Sans
- Freight Sans Pro
- Lane
- Source Sans Pro
- Robotolight
@zwacky
zwacky / string-vs-String.ts
Created October 21, 2016 22:34
TypeScript: string (primitive type) vs String (object type)
let objectType: String = 'first string';
let primitiveType: string = 'second string';
objectType = primitiveType; // √
primitiveType = objectType; // compiler error
@zwacky
zwacky / less-error-prone-dom-manipulation.js
Last active March 1, 2017 12:53
DOM manipulation without explicitly checking if they exist already in the DOM
// less error prone DOM manipulation
[].filter.call([document.querySelector('.single-selected-class')], item => item)
.forEach(item => item.blur());
@zwacky
zwacky / sizeup.lua
Last active March 17, 2017 10:35 — forked from josephholsten/sizeup.lua
SizeUp in Hammerspoon
-- === sizeup ===
--
-- SizeUp emulation for hammerspoon
--
-- To use, you can tweak the key bindings and the margins
local sizeup = { }
--------------
-- Bindings --
@zwacky
zwacky / fix_itunes_upload.sh
Created May 11, 2017 09:32
Stuck on Authenticating with iTunes Store (error code -22421)
# ISSUE:
# Stuck authenticating with Itunes Store
#
# ERROR:
# Archive upload failed due to the issues listed below.
# This action could not be completed. Try again (-22421)
cd ~
mv .itmstransporter/ .old_itmstransporter/
"/Applications/Xcode.app/Contents/Applications/Application Loader.app/Contents/itms/bin/iTMSTransporter"
@zwacky
zwacky / register-service-worker.js
Last active October 19, 2020 11:12
registers a service-worker which is wrapped in a promise that resolves with the value whether the service-worker has been updated or not
// make the whole serviceworker process into a promise so later on we can
// listen to it and in case new content is available a toast will be shown
window.isUpdateAvailable = new Promise(function(resolve, reject) {
// lazy way of disabling service workers while developing
if ('serviceWorker' in navigator && ['localhost', '127'].indexOf(location.hostname) === -1) {
// register service worker file
navigator.serviceWorker.register('service-worker.js')
.then(reg => {
reg.onupdatefound = () => {
const installingWorker = reg.installing;
@zwacky
zwacky / check-service-worker-update.ts
Last active September 13, 2021 10:11
the wrapped service-worker in index.html can then be called if any update is available
// listen to the service worker promise in index.html to see if there has been a new update.
// condition: the service-worker.js needs to have some kind of change - e.g. increment CACHE_VERSION.
window['isUpdateAvailable']
.then(isAvailable => {
if (isAvailable) {
const toast = this.toastCtrl.create({
message: 'New Update available! Reload the webapp to see the latest juicy changes.',
position: 'bottom',
showCloseButton: true,
});