View ptr.c
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdint.h>
void printbytes(void* ptr, size_t len) {
unsigned char *s = ptr;
for (int i = 0; i < len; i++)
printf("p[%d] = %02X\n", i, s[i]);
}
View nanboxing.c
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdint.h>
void printbytes(void* ptr) {
unsigned char *s = ptr;
for (int i = 0; i < sizeof(ptr); i++)
printf("p[%d] = %d\n", i, s[i]);
}
View ptrs.c
#include <stdio.h>
#include <stdlib.h>
int main(void) {
char *p = malloc(1);
unsigned char* ps = (void*)&p;
printf("testing: %lu\n", sizeof(p));
printf("testing: %p\n", p);
for (int i = 0; i < sizeof(p); i++)
printf("testing: p[%d] = %d\n", i, ps[i]);
View builtnan.c
#include <stdio.h>
#include <math.h>
int main(void) {
unsigned char bytes[8] = {0,0,0,0,0,0,248,127};
double d = *(double*)bytes;
printf("testing: %lu\n", sizeof(d));
printf("testing: %f\n", d);
}
View nan.c
#include <stdio.h>
#include <math.h>
int main(void) {
double d = NAN;
unsigned char* s = (unsigned char*)&d;
printf("testing: %lu\n", sizeof(d));
printf("testing: %f\n", d);
for (int i = 0; i < sizeof(d); i++)
printf("testing: nan[%d] = %d\n", i, s[i]);
View Enum Example.swift
enum Router: URLRequestConvertible {
static let baseURLString = "http://dev.example.com"
static var OAuthToken: String?
case MapView(Int)
case PhotoInfo(Int, ImageSize)
case Comments(Int, Int)
var URLRequest: NSURLRequest {
let (path: String, parameters: [String: AnyObject]) = {
View gist:55e75827a6b795e4507d
class ObserverSetEntry<Parameters> {
weak var object: AnyObject?
let f: AnyObject -> Parameters -> Void
init(object: AnyObject, f: AnyObject -> Parameters -> Void) {
self.object = object
self.f = f
}
}
View choose.vim
" find file in git repo
function! ChooseFile()
let dir = expand("%:h")
if empty(dir) | let dir = getcwd() | endif
let root = system("cd " . dir . " && git rev-parse --show-toplevel")
if v:shell_error != 0 | echo "Not in a git repo" | return | endif
let root = root[0:-2]
let selection = system("cd " . root . " && git ls-files -co --exclude-standard | choose")
View first.swift
var L = luaL_newstate()
luaL_openlibs(L)
luaL_loadstring(L, ("return function(x,y) return x + y end" as NSString).UTF8String)
lua_callk(L, 0, 1, 0, nil)
lua_pushnumber(L, 23)
lua_pushnumber(L, 45)
lua_callk(L, 2, 1, 0, nil)
var x = lua_tonumberx(L, -1, nil)