Skip to content

Instantly share code, notes, and snippets.

@douglas-vaz
douglas-vaz / BoyerMoore.java
Last active December 17, 2015 23:39
with trace output
/**
* Boyer-Moore string pattern matching
*
* @author Douglas
*/
import java.util.Map;
import java.util.HashMap;
public class BoyerMoore
@douglas-vaz
douglas-vaz / xor.py
Created September 14, 2013 18:32
Training for XOR via a recurrent neural network in Python using PyBrain
from pybrain.structure import RecurrentNetwork, FullConnection, LinearLayer, SigmoidLayer
from pybrain.datasets import SupervisedDataSet
from pybrain.supervised.trainers import BackpropTrainer
#Define network structure
network = RecurrentNetwork(name="XOR")
inputLayer = LinearLayer(2, name="Input")
hiddenLayer = SigmoidLayer(3, name="Hidden")
@douglas-vaz
douglas-vaz / bigram.c
Last active December 25, 2015 18:19
Glib Bigrams using a 2-level hash table
/**
-#Copyright (c) 2013 Douglas Vaz, Sharvari Bhosale
-#
-#Permission is hereby granted, free of charge, to any person obtaining a copy
-#of this software and associated documentation files (the "Software"), to deal
-#in the Software without restriction, including without limitation the rights
-#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-#copies of the Software, and to permit persons to whom the Software is
-#furnished to do so, subject to the following conditions:
-#
@douglas-vaz
douglas-vaz / gmp.pc.in
Created November 10, 2013 11:58
pkg-config file for GMP
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
Name: gmp
Description: GNU Multiple Precision Arithmetic Library
URL: http://gmplib.org
Version: @PACKAGE_VERSION@
Libs: -L${libdir} -lgmp
@douglas-vaz
douglas-vaz / gmp_add_pc.sh
Last active January 23, 2024 09:04
Add pkg-config support to the GMP source tree.
#!/bin/sh
#Add pkg-config support to GMP
#http://gmplib.org/list-archives/gmp-discuss/2013-May/005329.html
echo "Creating gmp.pc.in..."
echo """prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
@douglas-vaz
douglas-vaz / linux_io.c
Last active August 29, 2015 13:57
Fast file read in Linux
#include "linux_io.h"
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <wchar.h>
int main(void)
{
@douglas-vaz
douglas-vaz / matrix.py
Created April 21, 2014 19:05
Matrix operations in Python with a functional style
#!/usr/bin/python3
'''
Copyright (c) 2014 Douglas Vaz
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@douglas-vaz
douglas-vaz / rsa.py
Created May 6, 2014 19:48
RSA in Python
import math
def ExtendedEuclid(m, b, verbose=False):
a1, a2, a3 = 1, 0, m
b1, b2, b3 = 0, 1, b
if(verbose):
print("Q\tA1\tA2\tA3\tB1\tB2\tB3")
q = None
@douglas-vaz
douglas-vaz / substring.md
Created July 23, 2014 07:32
Bruteforce substring check
isSubstring(String A, String B) {
    for i = 0 to len(A)-len(B) {
        j = 0;
        while j < len(B) and A[i+j] == B[j] {
            j = j + 1;
        }
        if j == len(B) {
            return True;
 }

Keybase proof

I hereby claim:

  • I am douglas-vaz on github.
  • I am mistcrafter (https://keybase.io/mistcrafter) on keybase.
  • I have a public key whose fingerprint is 8F57 F022 A6B3 175A 5695 13C0 5B97 A84B 8B6E 4651

To claim this, I am signing this object: