Skip to content

Instantly share code, notes, and snippets.

@basic-calculus
basic-calculus / GADTS.hs
Created May 21, 2013 19:25
GADTs in Haskell
module GADTs (
Is (),
is,
rtol,
ltor
) where
import Unsafe.Coerce (unsafeCoerce)
data Is a b = Is deriving (Show, Eq)
@basic-calculus
basic-calculus / erlang_oop.rs
Created May 22, 2013 21:11
Erlang Style OOP in Rust
use core::comm;
use core::task;
// Erlang style OOP
pub struct Object {
priv input : comm::Chan <Input>
}
@basic-calculus
basic-calculus / visitor_pattern.rs
Created June 7, 2013 02:47
A simple prototype
// I heard that virtual calls can be faster than normal enum switching
// so I made a simple but flawed prototype implementation of enums
// with virtual calls.
trait MyEnumVisitor {
// Note that we can't have generic virtual functions (so that's
// one problem with this scheme)
fn onA (&self, uint);
fn onB (&self);
fn onC (&self);
fn onD (&self);
@basic-calculus
basic-calculus / low_level_hackery_variant.c
Created June 7, 2013 03:24
A lower level way of implementing enums. Could this be done in Rust?
#include <stdio.h>
// Uses GCC labels as values extension to implement enums
// Can this approach be used by the Rust compiler?
typedef struct {
void * (* tag) (void **);
union {
int a;
unsigned b;
$ ltrace eglretrace drawer.trace > ~/root/ltrace.log
__libc_start_main(0x4069f0, 2, 0x7fff92863338, 0x5cf460 <unfinished ...>
_ZNSt8ios_base4InitC1Ev(0x838c98, 0x7fff92863338, 0x7fff92863350, 3) = 0
__cxa_atexit(0x405f90, 0x838c98, 0x838618, 6) = 0
_ZNSt8ios_base4InitC1Ev(0x838db1, 0x7fff92863338, 0x7fff92863350, 4) = 2
__cxa_atexit(0x405f90, 0x838db1, 0x838618, 4) = 0
__cxa_atexit(0x40aaa0, 0x838d90, 0x838618, 5) = 0
__cxa_atexit(0x40aaa0, 0x838d80, 0x838618, 6) = 0
__cxa_atexit(0x5c67f0, 0x838ce0, 0x838618, 7) = 0
__cxa_atexit(0x5c9180, 0x838cc0, 0x838618, 8) = 0
@basic-calculus
basic-calculus / gist:c1b90061c81eb5a1fb5b
Created December 17, 2014 23:28
Badly performing SVG
This file has been truncated, but you can view the full file.
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" width="1200" height="754" onload="init(evt)" viewBox="0 0 1200 754" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs >
<linearGradient id="background" y1="0" y2="1" x1="0" x2="0" >
<stop stop-color="#eeeeee" offset="5%" />
<stop stop-color="#eeeeb0" offset="95%" />
</linearGradient>
</defs>
<style type="text/css">
pub fn exp(counter: usize, max_counter: usize, n: usize) -> usize {
let floor = (counter * n) / max_counter;
let ceil = 1 + (counter * n - 1) / max_counter;
let floor_exp = 1 << floor;
return floor_exp + (((1 << ceil) - floor_exp) * (counter * n - floor * max_counter)) / max_counter;
}
static inline void pause_times(unsigned spins){
unsigned iters = spins / 8U;
switch (spins % 8U) {
for (; iters > 0U; --iters) {
case 7: _mm_pause();
case 6: _mm_pause();
case 5: _mm_pause();
case 4: _mm_pause();
case 3: _mm_pause();
case 2: _mm_pause();
use std::str;
pub fn to_snakecase_ascii(a: &str) -> String {
let bytes = a
.as_bytes();
let len = bytes.len();
let ending_underscores = bytes
.iter()
public final class ContextCalls {
private ContextCalls() {
}
@Retention(RetentionPolicy.CLASS)
@Target({ElementType.METHOD})
@Indy(
bootstrap = @Bootstrap(clazz = Bootstrapper.class, method = "bootstrap"),