Skip to content

Instantly share code, notes, and snippets.

View cjameshuff's full-sized avatar

Christopher James Huff cjameshuff

View GitHub Profile
class ThreadmappedObject
def initialize(prototype, delegates = {})
@delegates = delegates
prototype.methods.each {|m|
(class << self; self; end).class_eval {
define_method(m) {|*args, &block|
deleg = @delegates.fetch(Thread.current) {@delegates[:default]}
if(deleg)
deleg.send(m, *args, &block)
else
// g++ minimal.cpp -o minimal `pkg-config --cflags --libs gtk+-3.0`
#include <gtk/gtk.h>
int main(int argc, char *argv[])
{
gtk_init(&argc, &argv);
GtkWidget * window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
gtk_widget_show(window);
gtk_main();
return 0;
2012-08-24 16:57:24.349 minimal[46878:903] -[NSEvent hasPreciseScrollingDeltas]: unrecognized selector sent to instance 0x101560b20
2012-08-24 16:57:24.351 minimal[46878:903] An uncaught exception was raised
2012-08-24 16:57:24.352 minimal[46878:903] -[NSEvent hasPreciseScrollingDeltas]: unrecognized selector sent to instance 0x101560b20
2012-08-24 16:57:24.353 minimal[46878:903] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSEvent hasPreciseScrollingDeltas]: unrecognized selector sent to instance 0x101560b20'
*** Call stack at first throw:
(
0 CoreFoundation 0x00007fff81f64784 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x00007fff80327f03 objc_exception_throw + 45
2 CoreFoundation 0x00007fff81fbe110 +[NSObject(NSObject) doesNotRecognizeSelector:] + 0
3 CoreFoundation 0x00007fff81f368ef ___forwarding___ + 751
struct Body {
body_id_t id;
double mass;
vec2 pos, tmp_pos;
vec2 vel, tmp_vel;
vec2 accel, prev_accel;
vec2 kv1, kv2, kv3, kv4;
vec2 kp1, kp2, kp3, kp4;
def open_data_file(fname)
puts "reading #{fname}"
fin = File.open(fname, "r")
line_iter = fin.lines("\r")
line_iter.each {|line|
# puts "@"
# puts line.chomp
; ModuleID = 'bc/main.cpp.bc'
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.6.0"
@str = private unnamed_addr constant [28 x i8] c"Plugin Initialize() called!\00"
define i32 @Initialize(i32 %argc, i8** nocapture %argv) nounwind uwtable ssp {
entry:
tail call void @llvm.dbg.value(metadata !{i32 %argc}, i64 0, metadata !15), !dbg !17
tail call void @llvm.dbg.value(metadata !{i8** %argv}, i64 0, metadata !16), !dbg !17
int op(int t) {return 2*t;}
int main(int argc, const char * argv[])
{
vector<int> data;
data.push_back(1);
data.push_back(2);
data.push_back(3);
data.push_back(4);
data.push_back(5);
int main(int argc, const char * argv[])
{
auto op = [](int t) -> int {return 2*t;};
vector<int> data {1, 2, 3, 4, 5};
for(auto & x : data)
printf("%d\n", op(x));
return EXIT_SUCCESS;
}
@cjameshuff
cjameshuff / cppformat.h
Created November 21, 2012 21:07
Extensible formatted strings for C++
// Usage:
// string s = (fstring("Testing...%d, %f, %d\n")% 1 % 2.0 % 42).str();
// cout << fstring("Testing...%d, %f, %d\n")% 1 % 2.0 % 42;
// cout << fstring("%s%d, %f, %d\n")% "Testing..." % 1 % 2.0 % 42;
// cout << fstring("%s%c%c%c%d, %f, %d\n")% "Testing" % '.' % '.' % '.' % 1 % 2.0 % 42;
// cout << fstring("%s%d, %f, %d\n")% string("Testing...") % 1 % 2.0 % 42;
#ifndef CPPFORMAT_H
#define CPPFORMAT_H
static inline fstring operator%(const fstring & lhs, float4 rhs) {
std::string fs = lhs.next_fmt("f");
fs = (fstring("(%s, %s, %s, %s)")% fs % fs % fs % fs).str();
return lhs.append((fstring(fs)% rhs.x % rhs.y % rhs.z % rhs.w).str());
}