Skip to content

Instantly share code, notes, and snippets.

View jl2's full-sized avatar

Jeremiah LaRocco jl2

View GitHub Profile
@jl2
jl2 / mkhelix.py
Created May 15, 2012 19:31
Python script using CATIA's COM interface to create a product structure containing 200 cubes arranged in a helix.
#!/usr/bin/env python3
import sys
import array
import math
import random
import os.path
import win32com.client
def get_catia():
@jl2
jl2 / gtrans.pl
Created March 30, 2011 19:48
Perl command line interface to Google Translate.
#!/usr/bin/perl
# By: Jeremiah LaRocco
# Use translate.google.com to translate between languages.
# Sample run:
# gtrans.pl --to french --from english This is a test
# Ceci est un test
#
use strict;
@jl2
jl2 / gist:928952
Created April 19, 2011 17:31
Use lxml and Python3 to validate XML against a DTD.The DTD can be specified on the command line, or as an optional parameter to the script.
#!/usr/bin/env python3
# Use lxml to validate XML against a DTD
import re
import sys
import os.path
import codecs
from lxml import etree
@jl2
jl2 / threadpool.cpp
Created March 27, 2011 18:13
Simple thread pool in C++.
#include <stdio.h>
#include <queue>
#include <unistd.h>
#include <pthread.h>
#include <stdlib.h>
// Base task for Tasks
;; -*- mode: Lisp; fill-column: 75; comment-column: 50; -*-
;;(declaim (optimize (speed 3) (safety 1) (debug 1)))
(setf *read-default-float-format* 'double-float)
#-quicklisp
(let ((quicklisp-init "/home/jeremiah/quicklisp/setup.lisp"))
(when (probe-file quicklisp-init)
(load quicklisp-init)))
@jl2
jl2 / readaudio.c
Created January 26, 2012 06:33
Use ffmpeg's libavcodec and libavformat to decode an audio file into an output buffer.
/*
readmp3.c
Copyright (c) 2012, Jeremiah LaRocco jeremiah.larocco@gmail.com
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
(ql:quickload :cl-glfw3)
(glfw:def-key-callback keyboard-handler (window key scancode action mod-keys)
(format t "Window ~a key ~a scancode ~a action ~a mod-keys ~a~%" window key scancode action mod-keys)
(when (eq key :escape)
(glfw:set-window-should-close window)))
(defun show-window (name)
(let ((win (glfw:create-window :title (format nil "GLFW Window (~a)" name)
:width 100
@jl2
jl2 / replace-python-region.el
Created November 10, 2011 17:45
Emacs Lisp to run the current region through Python, then replace the region with the output of the script.
(defun replace-python-exp ()
"Run the region as a Python script, kill the region, insert the output of the Python script."
(interactive)
(let* ((tmp-file (make-temp-file "tmppl"))
(rb (region-beginning))
(re (region-end))
(str (buffer-substring-no-properties rb re)))
(if (string-match "print" str)
(progn
(write-region rb re tmp-file nil 1)
(ql:quickload :cl-csv)
(ql:quickload :zip)
(ql:quickload :cl-strings)
;; Download transit data from this French site:
;; https://www.data.gouv.fr/fr/datasets/transport-donnees-gtfs/
(defun read-transit-data (&key (zip-file-path "~/Downloads/gtfs_current.zip"))
(flet ((csv-name-to-lisp (name)
(string-upcase (cl-strings:replace-all name "_" "-"))))
@jl2
jl2 / .emacs
Created November 8, 2019 18:54
(load "~/src/gtd/config")
;; Source: http://www.emacswiki.org/emacs-en/download/misc-cmds.el
(defun revert-buffer-no-confirm ()
"Revert buffer without confirmation."
(interactive)
(revert-buffer :ignore-auto :noconfirm))
(defun toggle-kbd-macro-recording-on ()