Skip to content

Instantly share code, notes, and snippets.

@1995eaton
1995eaton / slowsort.js
Created September 19, 2015 22:50
Sort an array ES6 style
function sort(array, sortReliability=10) {
'use strict';
return new Promise(resolve => {
let sorted = [];
Promise.all(array.map(e => {
return new Promise(resolve => {
setTimeout(() => {
sorted.push(e);
resolve(e);
}, e * sortReliability);
@1995eaton
1995eaton / extra.s
Last active August 29, 2015 14:27
GAS (x86-64/Linux ABI) helper functions
.intel_syntax noprefix
.text
.globl strlen; strlen:
xor rax, rax
cmpb [rdi], 0
je 1f
0:
add rax, 1
@1995eaton
1995eaton / argv.s
Created July 16, 2015 21:51
Argv printer in 64 bit assembly (System-V)
.intel_syntax noprefix
.text
.globl strlen; strlen:
xor rcx, rcx
mov rsi, rdi
jmp 0f
1:
inc rcx
@1995eaton
1995eaton / sockets.s
Created July 12, 2015 18:12
Linux socket messaging test in assembly
# compile with gcc -noprefix
# example usage:
# echo Hello server\! | netcat -c 127.0.0.1 8005
.intel_syntax noprefix
.set sys_socket, 41
.set sys_setsockopt, 54
.set sys_bind, 49
.set sys_listen, 50
@1995eaton
1995eaton / woodo
Created July 10, 2015 19:45
sudo woodo
#!/bin/sh
if [ $EUID -ne 0 ]; then
echo "It's a weird tree."
else
cat << "EOF"
@@@ @@@
@///@ /@@ @; @
@/ //@ / ;@ @;; @
@// ///@ @ ;;@ @;;;;;@
@1995eaton
1995eaton / json_parser.js
Created June 17, 2015 01:42
JSON parser written in JavaScript
module.exports = parse = (function() {
function isDigit(c) {
return c >= '0' && c <= '9';
}
function Parser(source) {
this.cursor = 0;
this.lineno = 1;
this.tokens = [];
this.lookahead = 0;
this.tokindex = 0;
@1995eaton
1995eaton / fizzbuzz.cc
Created May 15, 2015 22:03
FizzBuzz with C++ template metaprogramming
/*
g++ -std=c++14 -ftemplate-depth=2001 fizz.cc -o fizz 2>&1 >/dev/null | grep -oE '[0-9]+, (Fizz|Buzz|FizzBuzz|None)'
*/
#include <iostream>
struct Fizz;
struct Buzz;
struct FizzBuzz;
struct None;
@1995eaton
1995eaton / n_queens.c
Created May 10, 2015 05:28
N Queens Solver
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <time.h>
#define PRINT_SOLUTIONS
#define FANCY_PRINT
static inline void print_array(uint8_t *a, uint8_t n) {
putchar('[');
@1995eaton
1995eaton / ArgumentParser.java
Created May 4, 2015 06:52
CSC-151 Project 3
/**
* Argument parser for the FileUtilities class
*
* @author Jake Eaton
*/
public class ArgumentParser {
private static String helpLine =
"Usage: java FileUtilities COMMAND SHIFT FILE [-verbose]\n" +
"Encrypt/decrypt files using the shift cipher.\n\n" +
@1995eaton
1995eaton / regex_utils.cc
Created April 21, 2015 04:46
Regex Utils for C++11
#include <iostream>
#include <algorithm>
#include <vector>
#include <regex>
std::regex::flag_type parse_flags(const std::string& flag_str) {
std::regex::flag_type grammar = std::regex::ECMAScript;
std::regex::flag_type flags = grammar ^ grammar;
for (const auto& c: flag_str) {
switch (c) {