Skip to content

Instantly share code, notes, and snippets.

View kiljacken's full-sized avatar
🦀

Emil Lauridsen kiljacken

🦀
  • Danske Bank
  • Copenagen, Denmark
View GitHub Profile
// 1: Only my crate can implement *and* use it (plain visibilty)
pub(crate) trait AllocImpl {}
// 2: Only my module can implement the trait, others can use it
mod private {
pub trait Sealed {}
}
pub trait AllocImpl: private::Sealed {}
macro_rules! inner_ptr {
($gpuva:expr, $($f:tt)*) 0> ({
fn uninit_from<T: GPUStruct>(_: &GPUWeakPointer<T>) -> MaybeUninit<T::Raw<'static>> {
core::mem::MaybeUninit::uninit()
}
let tmp = uninit_from($gpuva);
// ... All the stuff up to and including `inner.offset_from(...)`
let off = inner.offset_from(...);
let outer = tmp.as_ptr();
fn out_from<T: GPUStruct, U>(gpuva: &GPUWeakPointer<T>) -> GPUWeakPointer<U> {
@kiljacken
kiljacken / ratelimit.nginxconf
Created March 9, 2017 12:36 — forked from ipmb/ratelimit.nginxconf
Nginx reverse proxy with rate limiting
upstream myapp {
server 127.0.0.1:8081;
}
limit_req_zone $binary_remote_addr zone=login:10m rate=1r/s;
server {
listen 443 ssl spdy;
server_name _;
@kiljacken
kiljacken / Fibo.java
Created November 5, 2015 13:06
Fibonacci in java using a horrible state machine.
public class Fibo
{
public static int fib(int n) {
State[] sss = new State[]{
(l) -> new int[]{ l[0], l[1], l[2], l[3], 0},
(l) -> new int[]{ l[0], l[1], l[3]>0?l[3]!=0?l[3]!=1?6:5:4:3, l[3], l[4]},
(l) -> new int[]{ l[0], l[1], l[3]>0?6:0, l[3], l[4]},
(l) -> new int[]{ -1, l[1], 0, l[3], l[4]},
(l) -> new int[]{ 0, l[1], 0, l[3], l[4]},
(l) -> new int[]{ 1, l[1], 0, l[3], l[4]},

Generics

Generics provide a method for creating functions and composite types that work across a wide range (read: all other) of types.

An example of a type definition using generics is the Option type:

type Option<T> enum {
	None,
	Some(T)
};
@kiljacken
kiljacken / draft.md
Last active August 29, 2015 14:25
Operation overloading spec draft

Rough sketch follows.

Operator overloading

To prevent the issue, from C++ style operator overloading, of an operator having to be defined on each type involved in th operation, we use based on the syntax for function declarations. This will allow independent definition without any duplication.

operator +(a: Vector2, b: Vector2): Vector2 {
    ...
#!/bin/bash
# variables
export GOPATH=$HOME/ark_go
# functions
info() {
echo "[ ] $@"
}
@kiljacken
kiljacken / main.rs
Last active August 29, 2015 14:10
main.rs
// History : Event[]
// Event : Time|Period, (Person|Object)[], Action[]
// Time : basic
// Period : Time, Time
//
use std::io;
enum LoopAction<'a> {
LZO_PUBLIC(int)
lzo1_decompress ( const lzo_bytep in , lzo_uint in_len,
lzo_bytep out, lzo_uintp out_len,
lzo_voidp wrkmem )
{
lzo_bytep op;
const lzo_bytep ip;
const lzo_bytep const ip_end = in + in_len;
lzo_uint t;
@kiljacken
kiljacken / gogame_example.go
Last active August 29, 2015 14:02
Update to work with value matrices
package main
import (
"github.com/go-gl/gl"
glfw "github.com/go-gl/glfw3"
"github.com/kiljacken/gogame"
"github.com/kiljacken/gogame/math"
"log"
)