Skip to content

Instantly share code, notes, and snippets.

@nielswind
nielswind / universal-module.js
Created February 22, 2012 19:01 — forked from ryanflorence/universal-module.js
Universal JavaScript Module, supports AMD (RequireJS), Node.js, and the browser.
(function (name, definition){
if (typeof define === 'function'){ // AMD
define(definition);
} else if (typeof module !== 'undefined' && module.exports) { // Node.js
module.exports = definition();
} else { // Browser
var theModule = definition(), global = this, old = global[name];
theModule.noConflict = function () {
global[name] = old;
return theModule;

Keybase proof

I hereby claim:

  • I am nielswind on github.
  • I am nielswind (https://keybase.io/nielswind) on keybase.
  • I have a public key whose fingerprint is D0F9 0D6E B153 796B 96FD 78FE 41F5 06AF D0F2 B1B8

To claim this, I am signing this object:

@nielswind
nielswind / gx
Last active February 3, 2022 13:53
#!/bin/bash
# fast select and change branch in git using fzf
set -euo pipefail
IFS=$'\n\t'
SEARCH="$*"
if [[ '-' == "${SEARCH}" ]];
then
git checkout -
exit $?
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
FILES=($*)
for val in "${FILES[@]}"; do
echo $val
#[[ $SRT =~ ((\.en)?(\.da)?\.srt$) ]] && echo "${BASH_REMATCH[1]}"
done
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
[[ -x `which fzf` ]] || (echo fzf required; exit 1)
export FZF_DEFAULT_OPTS='--height 40% --border'
B=$((git-notlocal) | fzf -1 --prompt 'checkout remote branch: ' | tr -s ' '|cut -d" " -f2)
[[ ! -e "$B" ]] && git checkout $B
#!/bin/bash
# list remote branches not having local branch with same name
set -euo pipefail
IFS=$'\n\t'
comm -23 <(git branch -r|cut -d"/" -f2-|sort|grep -v HEAD) <(git branch|cut -c3-|sort)
@nielswind
nielswind / motion_light_switch.yaml
Created March 17, 2022 18:17
Home Assistants Motion Light customized to use a switch
blueprint:
name: Motion-activated Light connected to Switch
description: Turn on a light when motion is detected.
domain: automation
source_url: https://github.com/home-assistant/core/blob/dev/homeassistant/components/automation/blueprints/motion_light.yaml
input:
motion_entity:
name: Motion Sensor
selector:
entity:
blueprint:
name: Garbage collection alert
description: Do action (alert) in case garbage collection is today at specific time
domain: automation
input:
time:
name: Time to test on
description: Test is run at configured time
default: '10:00:00'
selector:
blueprint:
name: deCONZ - Tradfri Shortcut Button - 4 state
description: 'Control anything using Tradfri Shortcut Button remote'
domain: automation
input:
remote:
name: Remote
description: Tradfri Shortcut Button to use
selector:
device:
@nielswind
nielswind / extract.sh
Last active April 19, 2023 09:52
extract (k8s) kind and optionally name from yaml
#!/usr/bin/env bash
# https://gist.githubusercontent.com/nielswind/8a9e2ae451ff6b690f9baff6a28851ba/raw/extract.sh
function depcheck() {
local DEPS=($*)
for cmd in "${DEPS[@]}"
do
[[ $(command -v $cmd 2>/dev/null) ]] || { echo -en "\n$cmd needs to be installed.";fail=1; }
done
[[ $fail -ne 1 ]] || { echo -en "\n${0}: Install the above and rerun this script\n";exit 1; }