Skip to content

Instantly share code, notes, and snippets.

@ormaaj
ormaaj / gist:9695693
Last active August 29, 2015 13:57
Mutable LINQ object wrapper
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Program {
public class NodeThing<T> {
public T Value;
public NodeThing() { }
#!/usr/bin/env bash
{ code=$(</dev/fd/0); } <<\EOF
${ZSH_VERSION+false} || emulate ksh
# eval showEnv (funcname) to display the state of "x" from a subprocess.
showEnv=$'bash -c \'${x+:} typeset x=unset; printf "subprocess %s: %s\\n" "$1" "$(typeset -p x)"\' --'
function printTest {
printf '%s test %d:\n' "$1" $((testnum++)) >&2
@ormaaj
ormaaj / cookiepwn.js
Last active August 29, 2015 14:02
cookie clicker bot
"use strict";
function cookiePwn(interval) {
return setInterval(function() {
Game.ClickCookie();
if ((Game.elderWrath >= 3 || !(Game.cookieClicks % 4)) && (!Game.clickFrenzy || Game.timersEl.elderFrenzy.style.display !== "block")) {
do {
Game.goldenCookie.spawn();
} while (Game.elderWrath < 3 && Game.goldenCookie.wrath);
Game.goldenCookie.click();
@ormaaj
ormaaj / evilReadLines.sh
Last active August 29, 2015 14:03
How not to read lines.
#!/usr/bin/env bash
# bash / ksh93 / mksh / zsh
# Don't do this!
${ZSH_VERSION+false} || emulate ksh
unset -v isKsh93
[[ ${!KSH_VERSION} == .sh.version ]] && isKsh93=
# Reads lines from file or stdin into arrayName, stupidly.
# evilReadLines arrayName [ file ]
@ormaaj
ormaaj / mergedir.ksh
Last active August 29, 2015 14:03
Directory merge / rename example
#!/usr/bin/env ksh
# Example for merging directories of files with possibly
# overlapping names into a single directory.
mkdir a b c new
touch a/{0..5} b/{3..7} c/{4..10}
echo before: */*
typeset -A files
for x in ~(N)./*/*; do
@ormaaj
ormaaj / magic.bash
Last active August 29, 2015 14:03
magic alias
bash -xO expand_aliases <<\EOF
alias magic='x=${BASH_COMMAND#"${BASH_ALIASES[magic]} "} command eval cmd=\$x \#'
magic oh hi there
printf 'The command that would have evaluated is: "%s"\n' "$cmd"
EOF
@ormaaj
ormaaj / clamp.cs
Created December 29, 2014 09:31
Generic clamp with configurable comparer
public static T Clamp<T>(this T value, T min, T max, IComparer<T> comparer = null) {
if (comparer.Equals(null))
comparer = Comparer<T>.Default;
if (comparer.Compare(value, min) <= 0) {
return min;
} else if (comparer.Compare(value, max) >= 0) {
return max;
} else {
return value;
foo=666
{ eval "$(</dev/fd/4)"; } 3<<EOF1 4<<EOF2
var=$(printf %q "$foo")
EOF1
$(</dev/fd/3)
echo "$var"
EOF2
@ormaaj
ormaaj / stdin
Last active August 29, 2015 14:13 — forked from anonymous/stdin
_jshon() {
shopt -s lastpipe
{ tee /dev/fd/3 | jshon "$@" >&4; } 3>&1 |
input=$(</dev/fd/0)
((PIPESTATUS)) || echo "$input"
} 4>&1
@ormaaj
ormaaj / stdin
Last active August 29, 2015 14:13 — forked from anonymous/stdin
_jshon() {
shopt -s lastpipe
typeset input status
{ tee /dev/fd/3 | jshon "$@" >&4; } 3>&1
input=$(</dev/fd/0)
((PIPESTATUS[0])) && printf %s "$input" >&2
return "${PIPESTATUS[0]}"
} 4>&1