Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / tic_tac_toe.cpp
Last active December 16, 2015 22:38
Simple AI implementation of Tic-Tac-Toe
#include <iostream>
using namespace std;
enum players {X = 1, O = 2};
class TicTacToe{
short state[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
const short strategy[9] = { 1, 3, 1, 3, 5, 3, 1, 3, 1};
@douglas-vaz
douglas-vaz / water_jug.cpp
Last active February 25, 2024 17:06
Solution to the Water Jug problem in C++
/**
* Based on the paper "A Heuristic for Solving the Generalized Water Jug Problem
* Florin Leon, Mihai Zaharia, Dan Galea
*/
#include <iostream>
using namespace std;
class Jug{
#!/usr/bin/python3
def whazaa(n):
for i in range(1,n):
if i % 15 == 0:
print('Whazaa')
elif i % 3 == 0:
print('Hip')
elif i % 5 == 0:
print('Hop')
else:
@douglas-vaz
douglas-vaz / graph_search.cpp
Created March 2, 2013 19:57
Breadth First Search and Depth First Search in C++
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
class Node{