Skip to content

Instantly share code, notes, and snippets.

View ScatteredRay's full-sized avatar

Indy Ray ScatteredRay

  • San Francisco, Ca
View GitHub Profile

Include Guards

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

is preferred to

@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);
}
};
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 }
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);
@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),* }) => (
@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');
f = (v) ->
v
x = [a, f
b, 2]
y = {a: f
b: 2}
funcall(
->
doShit()
if x
moreShit()
)
@ScatteredRay
ScatteredRay / gist:4158860
Created November 28, 2012 03:26
font-lock
(defun substitute-pattern (pattern symbol)
"Add a font lock hook to replace the matched part of PATTERN with the
Unicode symbol SYMBOL looked up with UNICODE-SYMBOL."
(interactive)
(font-lock-add-keywords
nil `((,pattern (0 (progn (put-text-property (match-beginning 1) (match-end 1)
'display ,symbol)
nil))))))
(defun substitute-patterns (patterns)
@ScatteredRay
ScatteredRay / cmakelists.txt
Created August 29, 2012 23:34
Two project CMake
SET (this_target PROJECT1)
PROJECT(${this_target})
...
ADD_EXECUTABLE(#{this_target} ...)
SET (this_target PROJECT2)
PROJECT(${this_target})