Skip to content

Instantly share code, notes, and snippets.

View breandan's full-sized avatar
📖
I may be slow to respond.

breandan breandan

📖
I may be slow to respond.
View GitHub Profile
import bisect
class NFA(object):
EPSILON = object()
ANY = object()
def __init__(self, start_state):
self.transitions = {}
self.final_states = set()
self._start_state = start_state
@mblondel
mblondel / lda_gibbs.py
Last active October 9, 2023 11:31
Latent Dirichlet Allocation with Gibbs sampler
"""
(C) Mathieu Blondel - 2010
License: BSD 3 clause
Implementation of the collapsed Gibbs sampler for
Latent Dirichlet Allocation, as described in
Finding scientifc topics (Griffiths and Steyvers)
"""
@rgov
rgov / debruijn.py
Last active November 14, 2023 07:37
de Bruijn sequence generator
def deBruijn(n, k):
'''
An implementation of the FKM algorithm for generating the de Bruijn
sequence containing all k-ary strings of length n, as described in
"Combinatorial Generation" by Frank Ruskey.
'''
a = [ 0 ] * (n + 1)
def gen(t, p):
@gatlin
gatlin / sat.hs
Created February 6, 2012 23:05
SAT Solver in Haskell
-- This is going to be on Hackage soon! https://github.com/gatlin/surely
{-# LANGUAGE BangPatterns #-}
-- |
-- Module : AI.Surely
-- Copyright : 2012 Gatlin Johnson
-- License : LGPL 3.0
-- Maintainer : rokenrol@gmail.com
-- Stability : experimental
@williame
williame / IntrusiveList.java
Created September 19, 2012 18:00
An intrusive list class for Java
public final class IntrusiveList<T> {
/** private constructor used by makeList() */
private IntrusiveList() {
t = null; // is null so we know this must be the head/tail
prev = next = this; // cyclic
}
/** returns a new head/tail pointer */
public static <T> IntrusiveList<T> makeList() {
@CodaFi
CodaFi / Algebra.pl
Last active January 2, 2021 11:14
Algebraic Laws in Prolog
% Introduce reflexive equality
refl(X, X).
% Introduce symmetrical equality
sym(X, Y) :-
refl(X, Y),
refl(Y, X).
% Identity of addition by zero
add_zero(N) :-
@staltz
staltz / introrx.md
Last active July 25, 2024 13:33
The introduction to Reactive Programming you've been missing
@ksaua
ksaua / build.gradle
Last active October 15, 2018 20:28
Gradle plugin which uses itself
// Let's say we have a gradle plugin. Now we want that gradle plugin project to actually use the exact plugin.
// There are probably multiple ways we can bootstrap this. One way is to build the jar, and use that, but that's boring.
// Here we show how we can have the plugin-project use the actual plugin we are building.
// :: We load the groovy script on runtime, only then are we able to apply the plugin
// Setup the groovy classpath. Start with our own files
def classpaths = [file('src/main/groovy').absolutePath, file('src/main/resources').absolutePath]
// The groovy script engine wants a string array
String[] classpathArray = classpaths.toArray(new String[classpaths.size()]);
// Start a groovy script engine with our classpaths
@jbgi
jbgi / Term.java
Last active September 25, 2023 00:45
Generalized Algebraic Data Types (GADT) in Java
import static java.lang.System.*;
import java.util.function.BiFunction;
import java.util.function.Function;
// Implementation of a pseudo-GADT in Java, translating the examples from
// http://www.cs.ox.ac.uk/ralf.hinze/publications/With.pdf
// The technique presented below is, in fact, just an encoding of a normal Algebraic Data Type
// using a variation of the visitor pattern + the application of the Yoneda lemma to make it
// isomorphic to the targeted 'GADT'.
@bolot
bolot / android.xml
Created June 22, 2015 18:57
A few live templates for Android Studio. On my Mac, this file lives in `~/Library/Preferences/AndroidStudioPreview1.3/templates/android.xml`. The location of the file depends on the version of Android Studio and the type of the operating system.
<templateSet group="android">
<template name="focvb" value="@Override&#10;public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {&#10; View view = inflater.inflate(R.layout.fragment_$END$, container, false);&#10; ButterKnife.inject(this, view);&#10; return view;&#10;}&#10;" description="Fragment onCreateView with ButterKnife" toReformat="true" toShortenFQNames="true">
<context>
<option name="JAVA_CODE" value="false" />
<option name="JAVA_STATEMENT" value="false" />
<option name="JAVA_EXPRESSION" value="true" />
<option name="JAVA_DECLARATION" value="true" />
<option name="JAVA_COMMENT" value="false" />
<option name="JAVA_STRING" value="false" />
<option name="COMPLETION" value="false" />