Skip to content

Instantly share code, notes, and snippets.

View ScatteredRay's full-sized avatar

Indy Ray ScatteredRay

  • San Francisco, Ca
View GitHub Profile
f = (v) ->
v
x = [a, f
b, 2]
y = {a: f
b: 2}
@ScatteredRay
ScatteredRay / LUT
Last active December 14, 2015 09:08
<html>
<body>
<canvas id="cvs" width="1024" height="32">
</canvas>
<script type="text/javascript">
var size = 32;
var cvs = document.getElementById("cvs");
cvs.width = size * size;
cvs.height = size;
var ctx = cvs.getContext('2d');
@ScatteredRay
ScatteredRay / test.rs
Created April 16, 2013 20:09
rust macro
trait Persistable {
fn persist_test(&self) -> int;
}
fn persist<T: Persistable>(val : T) {
io::println(fmt!("Val: %d", val.persist_test()));
}
macro_rules! object(
($cname:ident { $($tname:ident : $typ:ty),* }) => (
let window;
do str::as_c_str("Project Guava") |cstr| {
window = SDL::SDL_CreateWindow(cstr,
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
512, 512,
(SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN));
}
let context = SDL::SDL_GL_CreateContext(window);
render.rs:5:2: 6:1 error: type `gldevice::GLDevice` does not implement any method in scope named `init`
render.rs:5 device.init()
render.rs:6 }
@ScatteredRay
ScatteredRay / gist:7366353
Last active December 27, 2015 17:59
deleter templates.
template <typename T, void (*f)(T*)>
class delete_fun
{
public:
void operator()(T* obj) const
{
f(obj);
}
};

Include Guards

#ifndef HEADER_H
#define HEADER_H
//...
#endif //HEADER_H

is preferred to

@ScatteredRay
ScatteredRay / gist:0f1778aacfef0e75dcbd
Last active August 29, 2015 14:14
Static member existance check
template<typename T>
struct Has_My_Static {
typedef char yes[1];
typedef char no[2];
template<void*> struct exist_check;
template<typename U, U> struct type_check; // Use this for type checking.
#ifdef _MSC_VER
template<typename C> static yes& chk(C*, exist_check<(void*)&C::MyStatic>*);
#else
template<typename C> static yes& chk(C*, typeof(&C::MyStatic));
@ScatteredRay
ScatteredRay / Bar.cpp
Last active March 7, 2017 22:13
Circular dll build
#include <stdio.h>
#include "Foo.h"
#include "Baz.h"
#undef API
#define API __declspec(dllexport)
#include "Bar.h"
void Bar::Print() {
printf("Bar\n");
@ScatteredRay
ScatteredRay / Templ.cpp
Created June 18, 2017 08:35
Template partial specialization.
template <typename T, typename = void>
struct Foo;
// A
template <typename T>
struct Foo<unique_ptr<T>, typename std::enable_if<std::is_class<T>::value>::type> {...};
// B
template <typename T>
struct Foo<T, typename std::enable_if<std::is_class<T>::value>::type> {...};