Skip to content

Instantly share code, notes, and snippets.

@ezyang
ezyang / index.html
Created December 7, 2012 21:21
Text rotation in D3.js
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<script src="http://d3js.org/d3.v2.js"></script>
</head>
<body>
<script type="text/javascript">
/**
* A convenient function for taking a transformation (with rotation) on
@T31337
T31337 / CapCam.py
Last active January 11, 2017 12:49
ScreenRecorder&Microphone Audio Recorder Using FFMPEG & Python
#!/usr/bin/env python3
'''
This Script Is Mainly From A Youtube User,
I Only Modified It Slightly To Make It Python3 Compatable,
And Added Custom Microphone Recording Support
Original Source Code: http://pastebin.com/BY1t5AcC
Thanks To Youtube User NoBeansJose
License:
@FestivalBobcats
FestivalBobcats / gist:1323387
Created October 28, 2011 19:57
Underscore.js implementation of Cartesian Product
function cartesianProductOf(){
return _.reduce(arguments, function(mtrx, vals){
return _.reduce(vals, function(array, val){
return array.concat(
_.map(mtrx, function(row){ return row.concat(val); })
);
}, []);
}, [[]]);
}
@brantfaircloth
brantfaircloth / gist:260331
Created December 20, 2009 02:09
Python multiprocessing.JoinableQueue()
import os
import subprocess
import multiprocessing
def q_runner(n_procs, list_item, function, *args):
'''generic function used to start worker processes'''
task_queue = multiprocessing.Queue()
results_queue = multiprocessing.JoinableQueue()
if args:
arguments = (task_queue, results_queue,) + args
@guilhermemm
guilhermemm / k_shortest_paths.py
Last active May 12, 2021 02:47
Yen's K-Shortest Path Algorithm for NetworkX. Yen's algorithm computes single-source K-shortest loopless paths for a graph with non-negative edge cost. For more details, see http://en.m.wikipedia.org/wiki/Yen%27s_algorithm
# -*- coding: utf-8 -*-
"""
A NetworkX based implementation of Yen's algorithm for computing K-shortest paths.
Yen's algorithm computes single-source K-shortest loopless paths for a
graph with non-negative edge cost. For more details, see:
http://networkx.github.io
http://en.m.wikipedia.org/wiki/Yen%27s_algorithm
"""
__author__ = 'Guilherme Maia <guilhermemm@gmail.com>'
@jamesarosen
jamesarosen / two-travis-builds.md
Last active June 5, 2021 18:39
Running Two Very Different Travis Builds

I have a project that's been happily chugging along on Travis for a while. Its .travis.yml looks something like

script:
  - node_modules/ember-cli/bin/ember test

I wanted to add a second parallel build that did something very different. I didn't want to run ember test with a different Ember version or some other flag. I wanted to run a completely different command. Specifically, I wanted to run LicenseFinder's audit.

Travis has great docs on customizing parallel builds, but nothing describes how to do two completely different commands.

@pyos
pyos / ping.py
Last active November 16, 2021 15:31
import time
import random
import struct
import select
import socket
def chk(data):
x = sum(x << 8 if i % 2 else x for i, x in enumerate(data)) & 0xFFFFFFFF
x = (x >> 16) + (x & 0xFFFF)
@daien
daien / video_stabilize.py
Created January 2, 2012 18:23
Video stabilization with OpenCV and Hugin
#!/usr/bin/env python
""" Video stabilization with OpenCV (>=2.3) and Hugin
Adrien Gaidon
INRIA - 2012
TODO: add cropping, clean-up and improve doc-strings
"""
@mikkelam
mikkelam / hamilton.py
Last active October 29, 2022 07:21
Finds a hamiltonian path using networkx graph library in Python with a backtrack solution
import networkx as nx
def hamilton(G):
F = [(G,[list(G.nodes())[0]])]
n = G.number_of_nodes()
while F:
graph,path = F.pop()
confs = []
neighbors = (node for node in graph.neighbors(path[-1])
if node != path[-1]) #exclude self loops
@aembleton
aembleton / docx2md.md
Last active May 17, 2023 07:04 — forked from vdavez/docx2md.md
Convert a Word Document into MD

Converting a Word Document to Markdown in One Move

The Problem

A lot of important government documents are created and saved in Microsoft Word (*.docx). But Microsoft Word is a proprietary format, and it's not really useful for presenting documents on the web. So, I wanted to find a way to convert a .docx file into markdown.

Installing Pandoc

On a mac you can use homebrew by running the command brew install pandoc.

The Solution