Skip to content

Instantly share code, notes, and snippets.

View ayourtch's full-sized avatar
💭
hacking some Rust

Andrew Yourtchenko ayourtch

💭
hacking some Rust
View GitHub Profile
@ayourtch
ayourtch / gist:762039
Created January 1, 2011 21:56
checking malloc
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void checkzero(char *p, int size) {
while(--size) {
if(p[size]) {
printf("%p is non-zero at offset %d, the value is 0x%02hhx\n",
p, size, p[size]);
@ayourtch
ayourtch / gist:761926
Created January 1, 2011 19:07
Print stack trace with hex addresses
void bt() {
enum { BT_SIZE = 10 }; // Whatever big enough.
int i;
void *btbuf[BT_SIZE];
int btsize = backtrace(btbuf, BT_SIZE);
printf("Backtrace entries: %d\n", btsize);
for(i=0; i<btsize; i++) {
printf("%d: %p\n", i, btbuf[i]);
}
}
@ayourtch
ayourtch / gist:752460
Created December 23, 2010 02:19
Programming Challange from Erann Gat
-- Andrew Yourtchenko - Programming Challange from Erann Gat:
-- http://www.flownet.com/ron/papers/lisp-java/
-- Given a list of words and a list of phone numbers, find all the ways that
-- each phone number can be expressed as a list of words.
-- No batteries included. We have to define our own split() function.
function string:split(sep)
local sep, fields = sep or ":", {}
local pattern = string.format("([^%s]+)", sep)
self:gsub(pattern, function(c) fields[#fields+1] = c end)
diff --git a/Makefile b/Makefile
index 2d269fe..07ee2e9 100644
--- a/Makefile
+++ b/Makefile
@@ -107,4 +107,4 @@ sqlite3:
cd $(SQLITE3_DIR) && $(MAKE)
zeromq:
- cd $(ZEROMQ_DIR) && $(MAKE)
+ cd $(ZEROMQ_DIR) && ./configure --prefix=$(PREFIX) && $(MAKE)
-- http://lua-users.org/lists/lua-l/2002-04/msg00180.html
require 'socket'
local header =
[[HTTP/1.1 200 OK
Date: Fri, 19 Apr 2002 20:37:57 GMT
Server: Apache/1.3.23 (Darwin) mod_ssl/2.8.7 OpenSSL/0.9.6b
Cache-Control: max-age=60
Expires: Fri, 19 Apr 2002 20:38:57 GMT
function default_page(page, req, resp, params)
local form = {
{ "text", name = "textfield", id = "stTagInput", autocomplete = "off", class = "input-text",
value = params.test, title = "this is a text" },
{ "submit", value = "set", class = "input-btn" },
method = "post", action = "post", id = "UpdateForm"
}
page.myform = form