Skip to content

Instantly share code, notes, and snippets.

View agrif's full-sized avatar

agrif agrif

View GitHub Profile
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@agrif
agrif / square.hs
Last active December 24, 2015 04:59
checking if something is a square, in haskell
import Data.List
-- checks if a list of points forms a square, by checking:
-- * if |b - a| == |c - a|,
-- * if 0 == (b - a) . (c - a), and
-- * if a + (b - a) + (c - a) == d
-- (a, b, c, d are sorted by distance from a)
isSquare (a:as) = and [
mag2 (b - a) == mag2 (c - a),
0 == (b - a) `dot` (c - a),
@agrif
agrif / gist:7259813
Created November 1, 2013 01:28
secret eating!
MS4wMzkzfHwxMzgyNDAyOTUxMjU3OzEzODI0MDI5NTEyNTc7MTM4MzI2OTI4MDY1NXwwMTExMDB8NDMwODUxMDU4MjI5Mzk5Ljk0OzMzOTIzODg3NTE1OTYxNzMuNTszNzc2MDszNTE7MjE0MDM1NTgyMTM2MTE3LjcyOzMwMjM7LTE7LTE7MDswOzA7MDswOy0xOzA7MzUxOzA7MHwyMDAsMjAwLDEyOTQ4Mzk3MjY4NjMsMDswLDEyNSwyNTk3MDQ2MzA3MDEsMDsxNTAsMTUwLDQ1ODQzNTQwOTUsMDsxMDAsMTAwLDExMzg3MzQ4NTM4LDA7MTAwLDEwMCw0MDU3OTUzNTU3NiwwOzAsMTAwLDY3NzYwMTE2NzM0LDA7MCwxMDAsMjA2NzM4NDY3NjEzLDA7ODAsMTAwLDQ5ODAwMzc3NzU4NjUsMDs2MCw3MSwyNTg5OTE4MzU2NTc4NSwwOzcyLDcyLDE5NjI5NjY2ODgzOTc3MSwwO3w0NTAzNTk5NjI3MzcwNDk1OzQ1MDM1OTk2MjczNzA0OTU7MjgxNDc0OTc2NzEwNjU1OTs0NTAzNTczNzQ4NjQ0MzUxOzIyNTM0ODM0Mzg4OTkxOTk7MTM3NDM4OTUzNDczfDQ1MDM1OTc1MTMzNzU3NDM7MjI1NDg0NTQ4MDE4OTk1MTsxMDI3%21END%21
static inline void draw_triangle(OILImage *im, OILImage *tex, OILVertex v0, OILVertex v1, OILVertex v2, OILTriangleFlags flags) {
CPUPriv *priv = im->backend_data;
/* ranges of pixels that are affected */
int xmin, xmax, ymin, ymax;
/* the (signed) area of the triangle in normalized 2d space */
float area;
/* constant coefficients for alpha, beta, gamma */
float a12, a20, a01;
float b12, b20, b01;
float c12, c20, c01;
enum Expression {
Symbol(~str),
Compound(~str, ~[Expression])
}
fn standard_form(expr: &Expression) -> ~str {
match (*expr) {
Compound(~"List", ref items) => ~"list",
Compound(~"Blank", []) => ~"_",
use std::util::Void;
use std::ptr;
type Type1 = Void;
struct Type2;
fn main() {
let mut t1 : *Type1 = ptr::null();
let mut t2 : *Type2 = ptr::null();
#[feature(macro_rules)];
use std::str;
use std::io;
use std::vec;
// shim because Trait::<for T>::foo isn't implemented yet
fn hintfunc<T>(x: T) -> T { x }
macro_rules! hint(
($e:expr :: $t:ty) => (hintfunc::<$t>($e))
#!/usr/bin/env python3
import sys
import time
try:
_, iface = sys.argv
except ValueError:
print("usage: {} [iface]".format(sys.argv[0]))
sys.exit(1)
@agrif
agrif / church.rs
Last active December 31, 2015 05:09
#[feature(macro_rules)];
use std::fmt;
use std::ops;
///////////////////////////////////////
////////// Basic Definitions //////////
///////////////////////////////////////
// Zero numeral, and a Successor operator
@agrif
agrif / test.l
Created December 15, 2013 14:11
a quick llvm-backed compiled lisp
; lisp source file
(defun incr (x)
(+ x 1))
(defun main ()
(incr 42))