Skip to content

Instantly share code, notes, and snippets.

View rizo's full-sized avatar

Rizo I rizo

  • London, UK
View GitHub Profile
@rizo
rizo / stringtemplate.d
Created May 22, 2012 22:30 — forked from martindemello/stringtemplate.d
string templating in D
// first version - code demonstrating the basic idea.
// see below for a fuller-featured implementation
import std.string;
import std.range;
import std.stdio;
/* A very simple string templating system. Placeholders of the form
* %{variable} are replaced by the corresponding variable in the current
* scope.
@rizo
rizo / FANodeDraw.m
Last active December 11, 2015 11:08
// Draws a test finite automata node with CoreGraphics functions.
- (void)drawRect:(NSRect)rect
{
// Obtain the current context.
CGContextRef context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
// Set the color space.
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextSetFillColorSpace(context, colorSpace);
// http://rentzsch.tumblr.com/post/40806448108/ns-poor-mans-namespacing-for-objective-c
#ifndef NS
#ifdef NS_NAMESPACE
#define JRNS_CONCAT_TOKENS(a,b) a##_##b
#define JRNS_EVALUATE(a,b) JRNS_CONCAT_TOKENS(a,b)
#define NS(original_name) JRNS_EVALUATE(NS_NAMESPACE, original_name)
#else
#define NS(original_name) original_name
#endif
#endif
" Renders current LaTeX file.
function! LatexRender()
:w
:Latexmk
:LatexView
endfunction
autocmd FileType tex nnoremap <C-b> :call LatexRender()<CR> \
inoremap <C-b> <ESC>:call LatexRender()<CR>
//
// IRMMainView.m
// IRMPathIntersection
//
// Created by Rizo Isrof on 2/13/13.
// Copyright (c) 2013 IRM. All rights reserved.
//
#import "IRMMainView.h"
#import "GTREdgeShapes.h"
CGPoint OGCubicBezierTangent(CGFloat t, CGPoint P[static 4])
{
CGFloat a = -3 * (1 - t) * (1 - t),
b = 3 * (t - 1) * (3 * t - 1),
c = 3 * t * (2 - 3t),
d = 3 * t * t;
return (CGPoint) {
(a * P[0].x) + (b * P[1].x) + (c * P[2].x) + (d * P[3].x),
(a * P[0].y) + (b * P[1].y) + (c * P[2].y) + (d * P[3].y)
@rizo
rizo / gist:5016902
Last active December 14, 2015 02:49 — forked from anonymous/gist:5016843
int ledPin = 9;    // LED connected to digital pin 9
void setup()  {
 // nothing happens in setup
}
void loop()  {
 // fade in from min to max in increments of 5 points:
 for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
   // sets the value (range from 0 to 255):
// (defmacro ex1 (K) `(defun addnumber (X) (+ ,K X) ))
mixin template ex1(alias K)
{
int addnumber(int X)
{
return K + X;
}
}
// (defmacro ex0 (M K) `(progn (macroexpand-1 (,M ,K))))
@rizo
rizo / meta-macro.d
Last active December 14, 2015 08:49
import std.stdio;
// (defmacro ex2 (X) `(defmacro ,X (Y) `(defun ,Y (pprint ',Y))))
mixin template ex2(alias X)
{
mixin(`template `~X~`(alias Y)
{
mixin("void "~Y~"() { writeln(\""~ Y ~"\"); }");
}`);
}
def class_with_str(class_name, module_name):
"""
Returns a class object with the provided `class_name` in the scope of the `module_name`.
"""
try:
class_ = reduce(getattr, class_name.split("."), sys.modules[module_name])
except AttributeError:
raise NameError('Class "%s" does not exist!' % class_name)