Skip to content

Instantly share code, notes, and snippets.

@bjourne
bjourne / repeats.py
Created May 22, 2020 18:24
Finding Simple Repeats
import numpy as np
def suffix_array(seq):
if not seq:
return []
vocab = sorted(set(seq))
ch2idx = {ch: i for i, ch in enumerate(vocab)}
cls = np.array([ch2idx[t] for t in seq] + [-1])
@bjourne
bjourne / nbody.py
Last active December 24, 2019 16:58
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
class Body():
"""
This class contains adjustable parameters as attributes. These
parameters include current and previous positions, velocities, and
accelerations.
"""
rem in the emacs directory:
heat dir bin -sw 5150 -var var.MySource -cg bingroup -gg -dr INSTALLDIR -out bin.wxs
candle -out bin.wxsobj bin.wxs -dMySource="bin"
heat dir libexec -sw 5150 -var var.MySource -cg libexecgroup -gg -dr INSTALLDIR -out libexec.wxs
candle -out libexec.wxsobj libexec.wxs -dMySource="libexec"
heat dir share -sw 5150 -var var.MySource -cg sharegroup -gg -dr INSTALLDIR -out share.wxs
candle -out share.wxsobj share.wxs -dMySource="share"
<?xml version='1.0' encoding='windows-1252'?>
<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>
<Product
Name='Emacs $(var.Arch)'
Id='*'
UpgradeCode='$(var.UpgradeCode)'
Language='1033'
Codepage='1252'
Version='$(var.ProductVersion)'
Manufacturer="Free Software Foundation">
package utils;
import java.io.*;
import java.nio.*;
import java.nio.channels.*;
import java.util.Random;
import static java.lang.System.out;
import static java.nio.channels.FileChannel.MapMode.READ_WRITE;
public class TestWrite {
adj = {1 : {6, 8}, 2 : {7, 9}, 3 : {4, 8}, 4 : {3, 9, 0}, 6 : {1, 7, 0},
7 : {2, 6}, 8 : {1, 3}, 9 : {4, 2}, 0 : {4, 6}}
memo = {}
def allpaths2(at, n, tot):
if (at, n) in memo:
tot[0] += memo[at, n]
return
prev = tot[0]
if n == 0:
tot[0] += 1
from __future__ import print_function
import httplib2
import os
from apiclient import discovery
from apiclient.http import BatchHttpRequest
from datetime import datetime
from oauth2client import client
from oauth2client import tools
from oauth2client.file import Storage
@bjourne
bjourne / c_fast.c
Last active August 9, 2023 20:42
Faster LPathBench
/*
Copyright (c) 2014, Cosmin Gorgovan <cosmin [at] linux-geek [dot] org>
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
@bjourne
bjourne / gist:6219037
Created August 13, 2013 08:28
Update version numbers
import json
txt = """{
"version" : [0, 1, 0],
"list" : [
{"hi" : 33, "l" : [2, 3, 0], "mo" : { "version" : 3 }},
{"version": [3, 4, 5]}
],
"ad" : { "foo" : 123 }
}"""
@bjourne
bjourne / findnum.py
Created October 5, 2012 12:25
Test employee interview puzzle
from random import randint
from time import time
N_SOLS = 1
def binary_search(min, max):
n_bins = 0
while min <= max:
mid = (min + max) // 2
n_bins += 1
if mid < NUM:
min = mid + 1