Skip to content

Instantly share code, notes, and snippets.

@kpmiller
kpmiller / testlua.c
Last active July 22, 2022 01:41
C program to show execution from luaL_loadbuffer, tested with lua 5.3.1
//compiling on OSX 10.11
//export LUA=path/to/lua-5.3.1/src
//cc -I $LUA -L $LUA -l lua -o testlua testlua.c
#include <stdio.h>
#include <string.h>
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
char *luacode =
@kpmiller
kpmiller / testluatable.c
Created November 26, 2015 19:03
This is a simple example of calling a lua function that returns a table and retrieving the values out of the table
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
char *luacode =
"function f ( ) \n"
" print(\"hello\\n\") \n"
@kpmiller
kpmiller / gethist.py
Created November 26, 2016 18:09
Download historical stock data from yahoo
#!/usr/bin/python
import sys, os
if len(sys.argv) < 2:
print """Usage: %s symbol
where symbol is the stock symbol to fetch
""" % sys.argv[0]
sys.exit(1)
cmd = 'curl -o %s.csv http://ichart.yahoo.com/table.csv?s=%s&a=1&b=1&c=2016&d=11&e=22&f=2016' % (sys.argv[1], sys.argv[1])
@kpmiller
kpmiller / TOS-csv-optvol.py
Last active May 29, 2018 16:11
python 2.7 code for parsing CSV files saved from thinkorswim
#!/usr/bin/python
import csv, json, sys, re, os
import glob
try:
loglevel = int(os.environ["LOGLEVEL"])
except:
loglevel = 1
@kpmiller
kpmiller / TOS-csv-spreadfinder.py
Last active April 16, 2019 12:36
python 2.7 code that reads csv files saved from thinkorswim and applies a scan criteria to it
#!/usr/bin/python
import csv, json, sys, re, os
import glob
try:
loglevel = int(os.environ["LOGLEVEL"])
except:
loglevel = 1
@kpmiller
kpmiller / TOS-condorfinder-sc.py
Created January 16, 2017 05:02
scanner for iron condor trades matching some criteria
#!/usr/bin/python
import sys,os,glob,re,csv
try:
loglevel = int(os.environ["LOGLEVEL"])
except:
loglevel = 1
def Log(s, level=1):
@kpmiller
kpmiller / IVRank.py
Created October 5, 2017 23:47
An algorithm to find IVRank or IVPercentile
def GetIVRank(sessionid, symbol, useRank=True, debug=False):
#this returns an dictionary with the key as date, and the value as the raw IV
iv = GetImpliedVolatility(sessionid, symbol, debug=debug)
keys = iv.keys()
if len(keys)== 0:
return -1
keys.sort()
highest = 0.0
@kpmiller
kpmiller / quartzexample.py
Created September 11, 2018 18:58
Example of using core graphics from quartz to make a pdf file, using Apple built in python bindings
#!/usr/bin/python
#tested on 10.12 and 10.13
import Quartz
from Quartz.CoreGraphics import *
import Cocoa
import random
random.seed()
@kpmiller
kpmiller / rgbshades.py
Created April 1, 2019 18:24
python colorsys
#!/usr/bin/python
import colorsys
def PrintHex(v):
vv0 = v[0] * 255.0
vv1 = v[1] * 255.0
vv2 = v[2] * 255.0
print ( "#%02X%02X%02X" % (vv0, vv1, vv2))
@kpmiller
kpmiller / vscode_xcode.txt
Last active March 5, 2020 16:13
Make visual studio code's multi cursor settings match Xcode
in keybindings.json
[
{ "key": "shift+ctrl+down", "command": "cursorColumnSelectDown",
"when": "editorTextFocus" },
{ "key": "shift+ctrl+up", "command": "cursorColumnSelectUp",
"when": "editorTextFocus" },
{ "key": "PageUp", "command": "scrollPageUp",
"when": "editorTextFocus" },
{ "key": "PageDown", "command": "scrollPageDown",