Skip to content

Instantly share code, notes, and snippets.

View derrickturk's full-sized avatar
💭
(Come in under the shadow of this red rock)

Derrick Turk derrickturk

💭
(Come in under the shadow of this red rock)
View GitHub Profile
@derrickturk
derrickturk / dll_loader.hpp
Last active August 29, 2015 13:57
Simple DLL-loader class for Windows.
#ifndef DLL_LOADER_HPP
#include "windows.h"
#include <string>
#include <stdexcept>
#include <type_traits>
#include <utility>
// what!
@derrickturk
derrickturk / gist:9944152
Created April 2, 2014 22:03
command line options for msvc
cl /Wall /WX /Za /Zc:strictStrings,trigraphs /EHsc /volatile:iso /Feblah.exe
#include "dll_loader.hpp"
#include <iostream>
#include <vector>
#include <utility>
struct model {
double qi;
double Di;
double bi;
@derrickturk
derrickturk / with_pdf.R
Last active August 29, 2015 13:58
A hacky way to ease the burden of dealing with PDF output on windows.
kill.adobe <- function(filename)
{
old.warn <- options(warn=-1)
filter <- paste('/NH /FI "WINDOWTITLE eq ', filename, ' - Adobe Reader"', sep="")
res <- shell(paste("tasklist ", filter, ' | sed -e "s/ \\+/:/g" | cut -d ":" -f 2 | grep . | sed -e "s/^/\\/pid /g" | xargs taskkill', sep=""),
mustWork=NA, intern=TRUE)
options(old.warn)
grepl("SUCCESS", res[1])
@derrickturk
derrickturk / thereis.R
Created April 8, 2014 21:26
Like 'exists', but accepts unquoted names.
thereis <- function(x) exists(deparse(substitute(x)), parent.frame())
@derrickturk
derrickturk / any.cpp
Last active August 29, 2015 13:58
Fun with type erasure!
#include "anynum.hpp"
#include <iostream>
int main()
{
any_number a = 5, b = 6.7, c = b * 3.2, d = a / a;
std::cout << a << ", " << b << ", " << c << ", " << d << '\n';
std::cout << a.underlying_type().name() << ", "
<< b.underlying_type().name() << ", " << c.underlying_type().name()
<< ", " << d.underlying_type().name() << '\n';
@derrickturk
derrickturk / new.cpp
Created April 10, 2014 15:21
fun with custom operator new and delete
#include <iostream>
#include <memory>
#include <new>
#include <vector>
#include <cstddef>
#include <cstdlib>
struct wacky_tag_t {} wacky_tag;
void* operator new(std::size_t n)
@derrickturk
derrickturk / pillage298c.py
Created May 20, 2014 20:14
Pillage production data from IHS 98c (aka 298c) files.
from sys import argv, stderr, stdout, exit
def main(args):
fname = args[1]
stdout.write('UID\tName\tAPI\tLatitude\tLongitude\tMonth\tOil\tGas\tWater\tWells\n')
with open(fname) as f:
for w in well_production(f):
n_records = len(w['Month'])
for i in range(n_records):
stdout.write('\t'.join((w['UID'], w['Name'], w['API'],
@derrickturk
derrickturk / perfformations.sql
Last active August 29, 2015 14:02
tie perforations to zone tops, first fixing a silly format
select
t.UWI,
t.Formation,
t.Top,
t.NextTop as Base,
p.StartDepth,
p.EndDepth
from Perfs p
inner join VerticalTops t
on p.UWI = t.UWI
@derrickturk
derrickturk / gist:4d34b5bdbe07bbe11090
Created June 11, 2014 14:55
three-day rolling median
select * from
(
select MIN(x.ProdDate) as FirstProdDate, (SUM(x.OilVol) - MAX(x.OilVol) - MIN(x.OilVol)) As MedianOilVol
from (
select
ProdDate,
OilVol,
ROW_NUMBER() over (order by ProdDate) as RowNum