Skip to content

Instantly share code, notes, and snippets.

View ormaaj's full-sized avatar

Daniel Douglas ormaaj

View GitHub Profile
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <errno.h>
#define SIZE 4
int main(int argc, char **argv) {
char *basic = "8887";
char *dataStr = "1234 1a2b3c4e -10101010 0xdeadbeef";
char *endPtr = dataStr;
@ormaaj
ormaaj / validator.cs
Created October 21, 2013 09:08
validator
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;
using System.Xml.XPath;
using System.Reflection;
@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 / hashfunc.cs
Last active May 9, 2022 18:12
Generate a composite key from a list of fields
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 / 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 ]
#!/usr/bin/env ksh
typeset -a FUNCNAME
function FUNCNAME.get {
nameref self=${.sh.name}
if (( .sh.subscript < .sh.level )); then
trap "(( .sh.level -= .sh.subscript + 1 )); eval '(( .sh.level = ${.sh.level} ))' \; _=\${.sh.fun}" DEBUG
trap - DEBUG;
fi
@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