Skip to content

Instantly share code, notes, and snippets.

View jl2's full-sized avatar

Jeremiah LaRocco jl2

View GitHub Profile
@jl2
jl2 / format_tuple.cpp
Created July 26, 2013 23:12
std::tuple to string, using boost::format
#include <iostream>
#include <boost/format.hpp>
#include <tuple>
template<uint N, uint MAX, typename... Args> struct tuple_formatter {
static void format_tuple(boost::format &fmt, const std::tuple<Args...>& args) {
fmt % std::get<N>(args);
tuple_formatter<N+1,MAX,Args...>::format_tuple(fmt, args);
}
};
@jl2
jl2 / stupid_vector_bug.cpp
Created June 20, 2013 17:39
A stupid C++ bug. The insert() on line 23 has its last two parameters swapped, but "false" is silently converted to 0, so no compiler warnings/errors are raised.
#include <iostream>
#include <vector>
void Show(const std::vector<std::vector<bool>> &two_dim_vect) {
for (const auto &row : two_dim_vect) {
for (bool b : row) {
std::cout << b << " ";
}
std::cout << "\n";
}
@jl2
jl2 / CMakeLists.txt
Created June 5, 2013 23:35
Simple GLUT sample code
PROJECT(Basic CXX)
set(CMAKE_CXX_FLAGS "-std=c++11 -Wall -O3")
cmake_minimum_required(VERSION 2.6)
ADD_EXECUTABLE(Basic main.cpp)
TARGET_LINK_LIBRARIES(Basic freeglut opengl32 glu32)
@jl2
jl2 / Makefile
Created May 31, 2013 22:39
Download the latest version of Chromium for Windows using C++ and libCurl. Very similar to the C version.
uchrome.exe: main.cpp Makefile
g++ -Wall -O3 -m64 -std=c++11 -I d:\mingw\include -o uchrome.exe main.cpp -Ld:/mingw/bin -lcurl -lws2_32 -lwinmm -Ld:/mingw/lib64 -lssl
@jl2
jl2 / file2dir.py
Created May 6, 2013 16:56
Create a directory for every file in the specified directory and move the file into it.
#!/usr/bin/env python3
import os
import sys
import glob
import shutil
import argparse
from stat import *
def main(args):
@jl2
jl2 / basincam.cpp
Last active December 16, 2015 14:29
Create movie files from Arapahoe Basin's webcams.
/*
* basincam.cpp
* Copyright (c) 2013, Jeremiah LaRocco [email protected]
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
@jl2
jl2 / abasincam.lisp
Last active December 16, 2015 09:49
Download the ABasin web cam images and make a time lapse movie out of them. In Python and an attempt at Common Lisp
(ql:quickload "drakma")
(defun download-image (url idx)
(let*
((outfname (format nil "lisp_images/~6,'0d.jpg" idx))
(instream (drakma:http-request url :want-stream t :force-binary t))
(buf (make-array 4096 :element-type (stream-element-type instream))))
(with-open-file (outstream outfname
:direction :output
@jl2
jl2 / Makefile
Created April 4, 2013 22:13
First attempt to automate creation of images like http://www.flickr.com/photos/rtadlock/8611207319/in/contacts/ In a Gist for now, will make a repo later tonight.
testing: testing.cpp Makefile
g++ -std=c++11 -o testing testing.cpp -I/home/jl2/oss_code/-pthread `GraphicsMagick++-config --cppflags --cxxflags --ldflags --libs` -lboost_system -lboost_program_options
@jl2
jl2 / uchrome.c
Created March 4, 2013 21:09
Use libcurl from C to download and install the latest build of Chromium.
/*
* uchrome.c
* Copyright (c) 2013, Jeremiah LaRocco [email protected]
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
@jl2
jl2 / Makefile
Last active November 4, 2017 20:39
A simple trie data structure in C++.
trie: main.cpp Makefile
clang++ -O3 -std=c++11 -stdlib=libc++ -Wall -o trie main.cpp -lboost_system