Skip to content

Instantly share code, notes, and snippets.

@kristate
kristate / poller.rs
Created March 11, 2018 16:19
Not sure if I will ever have any use for this.
enum PollerEnum {
Item(()),
Timer,
}
struct Poller {
timer: Interval,
inner_iter: Option<Box<futures::stream::IterOk<std::vec::IntoIter<()>, std::io::Error>>>,
}
@kristate
kristate / select_ws.bat
Created July 31, 2017 12:03 — forked from mback2k/select_ws.bat
select_ws example program
mingw32-gcc select_ws.c -Wl,-lws2_32 -g -pedantic -Wall -W -Wpointer-arith -Wwrite-strings -Wunused -Wshadow -Winline -Wnested-externs -Wmissing-declarations -Wmissing-prototypes -Wno-long-long -Wfloat-equal -Wno-multichar -Wsign-compare -Wundef -Wno-format-nonliteral -Wendif-labels -Wstrict-prototypes -Wdeclaration-after-statement -Wstrict-aliasing=3 -Wcast-align -Wtype-limits -Wold-style-declaration -Wmissing-parameter-type -Wempty-body -Wclobbered -Wignored-qualifiers -Wconversion -Wno-sign-conversion -Wvla -Wno-pedantic-ms-format -Wno-system-headers -o select_ws.exe
@kristate
kristate / eoc.c
Created June 27, 2017 08:25
Elias omega coding など
/* (c) kristopher tate ; all rights resevered. */
static uint16_t eoc_encode(uint16_t code, uint8_t start, uint8_t binrep[ROUTE_LENGTH])
{
int i;
int pos = 0;
uint8_t bits[4];
while (code > 1) {
int len = 0;
for (int temp = code; temp > 0; temp >>= 1) { /*calculate 1+floor(log2(num))*/
len++;
@kristate
kristate / std_map.mm
Created February 3, 2013 01:55
NSMapTableは本当に面倒いなー。C++は嫌なんやけど、この場合には std::map は良さげ。
/*
* How to use std::map instead of NSMapTable -- assuming ARC
* Objective-C++はクレージーしすぎる件w まあいいか。
* License: Public-Domain
*/
#ifdef __cplusplus
#include <map>
#endif
@kristate
kristate / gist:4699204
Last active December 22, 2017 23:57
A note on how to work with ARC, Objective-C blocks and C libraries. (久利寿でも分かりにくかったので共有いたします!)
//A note on how to work with ARC, Objective-C blocks and C libraries.
//with love from kristopher on a Sunday (2013.2.3@5:46a JST)
//License: Public-Domain
//あるLibraryのAsync Callback TypeDef
typedef void (somelibrary_doasync_cb)(int state, uintptr_t user_data);
//あるLibraryのAsync Function
void somelibrary_doasync(somelibrary_doasync_cb callback, uintptr_t user_data);
//われわれのBlockDef
typedef void (^StatusHandlerBlock)(int state);
@kristate
kristate / input_to_array.py
Created January 20, 2013 16:52
read a file and dump it as an array of characters for easy embedding -- couldn't find something similar so I wrote this -- may it also be useful to you!
'''
* input_to_array.py
(c) 2013 kristopher tate -- http://kristopher.jp
* read a file and dump it as an array of characters for easy embedding
* couldn't find something similar so I wrote this -- may it also be useful to you!
* MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
@kristate
kristate / gist:4357393
Created December 22, 2012 03:43
Unique Download Filename
NSString* fname = [target lastPathComponent];
NSString* fnameNoExt = [fname stringByDeletingPathExtension];
NSString* extension = [fname pathExtension];
int fileIndex = 1;
while ([[NSFileManager defaultManager] fileExistsAtPath: [folder stringByAppendingPathComponent:fname]])
{
//NSLog(@"FNAME : %@",fname);
fname = [NSString stringWithFormat:@"%@ (%d).%@", fnameNoExt, fileIndex, extension];
//NSLog(@"Setting filename to :: %@",fname);
@kristate
kristate / env_copy_test.bench
Created September 16, 2012 18:41
test on how to copy worker env for spawning
kristate@www12294uf:~$ gcc test1.c; ./a.out
type_a: 1.900000 seconds
type_b: 1.420000 seconds
kristate@www12294uf:~$ gcc test1.c; ./a.out
type_a: 1.790000 seconds
type_b: 1.430000 seconds
kristate@www12294uf:~$ gcc test1.c; ./a.out
type_a: 1.480000 seconds
type_b: 1.480000 seconds
kristate@www12294uf:~$ gcc test1.c; ./a.out