Skip to content

Instantly share code, notes, and snippets.

View H2CO3's full-sized avatar
🦀

Árpád Goretity  H2CO3

🦀
View GitHub Profile
//
// WARNING:
// a "Greeter" class is a typical BAD example,
// an anti-pattern. You shouldn't be making this
// a class IRL. I've only come up with this
// example because I've run out of creative sauce.
//
function Greeter(msg) {
var self = {
#!/usr/local/bin/spn
# Playing around with differential geometry is fun!
let derivative = function derivative(fn) {
return function(x0) {
let f = fn;
let dx = 1.0e-5;
let x = x0 + dx;
let y0 = f(x0), y = f(x);
@H2CO3
H2CO3 / cplx_mat.js
Last active August 29, 2015 14:06
Playin' around with complex matrices...
# Computes conjugate transpose of M
let conjTransp = function conjTransp(M) {
return map(range(sizeof M[0]), function(row) {
return map(range(sizeof M), function(col) {
return cplx_conj(M[col][row]);
});
});
};
# Helper for cplxMatMul
@H2CO3
H2CO3 / hash_cfdictionary.c
Last active August 29, 2015 14:07
NSMutableDictionary vs. CFMutableDictionaryRef vs. SpnHashMap – a top-off-my-head benchmark
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#import <CoreFoundation/CoreFoundation.h>
#define KEYSIZE (10 + 1 + 1)
int main()
{
@H2CO3
H2CO3 / fib.c
Last active August 29, 2015 14:09
Argument passing benchmark
#include <stdio.h>
unsigned long fib1(unsigned long n)
{
return n < 2 ? 1 : fib1(n - 1) + fib1(n - 2);
}
unsigned long fib2(unsigned long n, unsigned long m)
{
return n < 2 ? 1 : fib2(n - 1, m) + fib2(n - 2, m);
@H2CO3
H2CO3 / js2betterjs.js
Last active August 29, 2015 14:10
I just read in the description of Google's Closure compiler that it "compiles JavaScript to better JavaScript".
// This is how H2CO3 writes a JavaScript to better JavaScript compiler
function compile(source) {
return ""; // no JavaScript is definitely better than some JavaScript
}
// Usage example
var exampleSource = "window.alert('foo');";
eval(compile(exampleSource)); // extra advantage: no more annoying alert windows!
@H2CO3
H2CO3 / README.txt
Created November 24, 2014 08:08
[BUGFIX] – Sparkling parser crashes
This is a diff for Sparkling @ commit 665e00d51dae99493958fb2e25fe5d56ffb66a15
Fixes some crashes in the parser caused by infinite recursion upon encountering certain types of malformed Sparkling source.
Bugs found using `zzuf`, a fuzzing tool.
This is a patch and not a proper commit because I'm rewriting the parser in the meantime, and I don't want to deal with conflicts. They will be undone anyway – this patch is just a temporary (but nonehteless important) bugfix.
@H2CO3
H2CO3 / sparkling-eval.el
Created December 21, 2014 01:08
Sparkling inline evaluation
;; C-c C-e
(defun sparkling-eval-replace-expr (start end)
"Evaluate the contents of the selected region (or the region between START and END) as an expression and replace it with the result."
(interactive "r")
(call-process "spn" nil t nil "-e" (delete-and-extract-region start end))
)
;; C-c C-r
(defun sparkling-eval-replace-stmt (start end)
"Evaluate the contents of the selected region (or the region between START and END) as statements and replace it with the result."
@H2CO3
H2CO3 / SpnMap.hpp
Created January 13, 2015 18:20
SpnHashMap, rewritten in C++
//
// SpnMap: Sparkling's hash table, in C++
// Created by Arpad Goretity on 13/01/2015
//
#include <vector>
#include <utility>
#include <cstdint>
#include <climits>
#include <cassert>
@H2CO3
H2CO3 / RubyQuiz7.cpp
Created January 14, 2015 12:01
My solution to RubyQuiz #7 in C++. http://rubyquiz.com/quiz7.html
#include <vector>
#include <array>
#include <unordered_map>
#include <string>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <utility>
#include <memory>
#include <functional>