Skip to content

Instantly share code, notes, and snippets.

🤔

Dan Douglas ormaaj

🤔
Block or report user

Report or block ormaaj

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ormaaj
ormaaj / gist:9695693
Last active Aug 29, 2015
Mutable LINQ object wrapper
View gist:9695693
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Program {
public class NodeThing<T> {
public T Value;
public NodeThing() { }
View exportscope
#!/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 / hashfunc.cs
Created May 5, 2014
Generate a composite key from a list of fields
View hashfunc.cs
/// <summary>
/// Generate a deterministic key from a vector of strings
/// </summary>
/// <param name="pRecordProps"></param>
/// <returns>base64-encoded key</returns>
public static string GetKeyFromRecord<T>(IEnumerable<string> pRecordProps) where T : HashAlgorithm, new() {
using (T hashAlg = new T()) {
IEnumerable<byte> result = pRecordProps.Select(x => hashAlg.ComputeHash(Encoding.UTF8.GetBytes(x ?? string.Empty))).SelectMany(y => y);
return Convert.ToBase64String(hashAlg.ComputeHash(result.ToArray()));
}
@ormaaj
ormaaj / gist:c050b4e6c7068b9e182a
Created May 7, 2014
funny busted find command
View gist:c050b4e6c7068b9e182a
function fixperms {
typeset -a paths
while ! ${1+false}; do
case $1 in
-u)
if [[ -n $2 ]]; then
typeset _chmodUserGroup=$2
command shift 2
else
@ormaaj
ormaaj / cookiepwn.js
Last active Aug 29, 2015
cookie clicker bot
View cookiepwn.js
"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 Aug 29, 2015
How not to read lines.
View evilReadLines.sh
#!/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 / magic.bash
Last active Aug 29, 2015
magic alias
View magic.bash
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 / mergedir.ksh
Last active Aug 29, 2015
Directory merge / rename example
View mergedir.ksh
#!/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 / clamp.cs
Created Dec 29, 2014
Generic clamp with configurable comparer
View clamp.cs
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;
View gist:ad4ec937ef316f7aa5ff
foo=666
{ eval "$(</dev/fd/4)"; } 3<<EOF1 4<<EOF2
var=$(printf %q "$foo")
EOF1
$(</dev/fd/3)
echo "$var"
EOF2
You can’t perform that action at this time.