This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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 = { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
#import <CoreFoundation/CoreFoundation.h> | |
#define KEYSIZE (10 + 1 + 1) | |
int main() | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <vector> | |
#include <array> | |
#include <unordered_map> | |
#include <string> | |
#include <iostream> | |
#include <fstream> | |
#include <algorithm> | |
#include <utility> | |
#include <memory> | |
#include <functional> |