Skip to content

Instantly share code, notes, and snippets.

@hltbra
hltbra / b.c
Created April 6, 2020 17:13
Demo of Lua integrated with C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
int main (int argc, char *argv[]) {
if (argc < 3) {
fprintf(stderr, "Missing arguments. Use it like ./program <a> <b>\n");
import ast
code = """
import foo
a = 1 + 2
b = "a" + "b" * 3
@hltbra
hltbra / cdredis.c
Created May 24, 2019 21:19
Experiments using ae.c/anet.c with Cython + dredis
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include "ae.h"
#include "anet.h"
#include "cdredis.h"
def scrape_listing():
for link in get_links(LISTING_URL):
scrape_link(link)
def scrape_link(url):
resp = requests.get(url)
info = get_link_info(resp.content)
save('link', info)
schedule('scrape_link', 'http://example.com', seconds=0)
for _ in range(10):
schedule('scrape_link', link, seconds=0)
@starting_task
def scrape_listing():
for link in get_links(LISTING_URL):
schedule('scrape_link', link, seconds=0)
@subtask
def scrape_link(url):
resp = requests.get(url)
info = get_link_info(resp.content)
@hltbra
hltbra / ysh.py
Last active January 4, 2019 05:19
Basic implementation of a shell in Python. This is from a talk I gave at YipitData on August 29, 2018.
# REPL
# read, eval, print, loop program
import os
import subprocess
import shlex
import sys
last_returncode = 0
try:
@hltbra
hltbra / dynamic-python.ipynb
Created August 1, 2018 22:17
Tech talk at Yipit about Python dynamic features - 2018/08/01
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@hltbra
hltbra / spreadsheet.py
Last active July 26, 2018 22:13
playing with metaprogramming to create a spreasheet-like DSL. This is an extension of a Coding Dojo performed at Yipit (https://github.com/Yipit/yipit-dojo/tree/master/2018-07-25)
from collections import defaultdict
class BaseCell(object):
def __init__(self, value):
self.value = value
def __add__(self, other):
if not isinstance(other, Cell):
other = BaseCell(other)