Skip to content

Instantly share code, notes, and snippets.

@Idorobots
Idorobots / gist:8163848
Last active January 1, 2016 15:19
Why OOP when you can NOOP?
private auto typeDispatch(T, Cs...)(T value, Cs callbacks) {
/*static*/ foreach(i, C; Cs) {
if((cast(ParameterTypeTuple!C[0]) value) !is null) {
return callbacks[i](cast(ParameterTypeTuple!C[0]) value);
}
}
throw new SemanticError("Can't compile that!");
}
// ...
@Idorobots
Idorobots / gist:11387381
Created April 28, 2014 23:51
Half-assed ID3 attempt.
fun name (n, v) = n;
fun vals (n, v) = v;
fun get([], a) = 0
| get((b, v) :: tail, a) = if a = b then v else get(tail, a);
fun ig(a, S, C) =
(* TODO :( *)
C(S, name a);
@Idorobots
Idorobots / gist:11405377
Last active August 29, 2015 14:00
Half-assed apriori attempt.
module apriori;
import std.stdio;
import std.string;
import std.conv;
bool contains(A, E)(A array, E element) {
foreach(E e; array) {
if(e == element) return true;
}
@Idorobots
Idorobots / gist:8d487e3bd43b44d31a33
Last active August 29, 2015 14:01
Simple TCP Echo client.
#include <signal.h>
#include <errno.h>
#include <pthread.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@Idorobots
Idorobots / gist:668e7c43bc1d8a2776a6
Created July 15, 2014 15:41
Parallella temp script
#!/bin/bash
raw=`cat /sys/bus/iio/devices/iio:device0/in_temp0_raw`
offset=`cat /sys/bus/iio/devices/iio:device0/in_temp0_offset`
scale=`cat /sys/bus/iio/devices/iio:device0/in_temp0_scale`
c_temp=`echo "scale=1;(($raw + $offset) * $scale) / 1000" | bc`
f_temp=`echo "scale=1;(($c_temp * 9) / 5) + 32" | bc`
echo
echo "Zynq Temp: $c_temp C / $f_temp F"
@Idorobots
Idorobots / gist:ad4d749074f1d3715019
Last active August 29, 2015 14:06
PKGBUILD for emscripten-git
# Contributor: Vlad Kolotvin <[email protected]>
# Maintainer: Stefan Husmann <[email protected]>
pkgname=emscripten-git
pkgver=11558
pkgrel=1
pkgdesc="LLVM-to-JavaScript compiler"
arch=('i686' 'x86_64')
url="http://emscripten.org"
license=('custom')
(ns component.core
(:require [com.stuartsierra.component :as component]))
(defrecord AppConfig [file path]
component/Lifecycle
(start [this]
(println "Starting AppConfig!")
this)
@Idorobots
Idorobots / file.d
Last active August 29, 2015 14:13
Graham scan
module graham;
import std.algorithm;
import std.array;
import std.math;
import std.conv;
struct Point {
double x;
double y;
@Idorobots
Idorobots / gist:293ea077ab0d578cb16d
Created March 15, 2015 22:03
Formants blah blah blah
|------------+-------+--------+--------|
| samogłoska | F1 | F2 | F3 |
|------------+-------+--------+--------|
| a | 713.4 | 1202.3 | 2570.9 |
| | 623.5 | 1141.7 | 2423.0 |
| | 622.7 | 1175.4 | 2652.8 |
|------------+-------+--------+--------|
| e | 559.0 | 1665.1 | 2449.1 |
| | 546.8 | 1727.7 | 2521.8 |
| | 543.4 | 1737.3 | 2410.7 |
@Idorobots
Idorobots / idonteven.scm
Created July 21, 2015 14:24
I just lost my abbility to even...
;; Code:
'(letrec ((even? (lambda (x) (if (= 0 x) 't (odd? (- x 1)))))
(odd? (lambda (x) (if (= 0 x) 'n (even? (- x 1))))))
(even? 7))
;; Compiled code:
'(let ((__evenQUEST '()) (__oddQUEST '()))
(do (set!
__evenQUEST
(lambda (__x __cont1)