This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" 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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// IRMMainView.m | |
// IRMPathIntersection | |
// | |
// Created by Rizo Isrof on 2/13/13. | |
// Copyright (c) 2013 IRM. All rights reserved. | |
// | |
#import "IRMMainView.h" | |
#import "GTREdgeShapes.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// (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)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ~"\"); }"); | |
}`); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
OlderNewer