Skip to content

Instantly share code, notes, and snippets.

View andrefreitas's full-sized avatar

André Freitas andrefreitas

View GitHub Profile
@andrefreitas
andrefreitas / build.xml
Last active December 14, 2015 16:58
An example of build.xml for ant to run junit tests
<project name="Cflow" default="cflow-tests" basedir=".">
<target name="cflow-tests">
<junit printsummary="yes" haltonfailure="yes">
<classpath>
<pathelement location="libs/junit.jar"/>
<pathelement location="."/>
</classpath>
<test name="cflow.tests.TestDFA" haltonfailure="no" outfile="result">
<formatter type="plain"/>
@andrefreitas
andrefreitas / client.py
Created March 16, 2013 02:40
Multicaste in Python
import socket
MCAST_GRP = '224.1.1.1'
MCAST_PORT = 5007
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2)
sock.sendto("robot", (MCAST_GRP, MCAST_PORT))
@andrefreitas
andrefreitas / homework3.py
Created April 1, 2013 01:19
COMP - Homework3
from lexer import Lexer
from rdp_parser import Parser
tokens={
"INT":"[0-9]+",
"ADD":"\+",
"SUB":"-",
"MUL":"\*",
"DIV":"/"
}
-- Remove the old score from that costumer in that product
DROP TRIGGER IF EXISTS new_score_before ON stores;
DROP FUNCTION IF EXISTS new_score_before();
CREATE OR REPLACE FUNCTION new_score_before() RETURNS trigger as $$
BEGIN
DELETE FROM products_scores
WHERE NEW.user_id = products_scores.user_id AND
NEW.product_id = products_scores.product_id;
RETURN NEW;
END;
public boolean areAdjacent(int oldX, int oldY, int newX,int newY){
int deltaX=newX-oldX;
int deltaY=newY-oldY;
if(deltaY==0 && deltaX!=0){
for(int i=oldX+deltaX; i<7; i=i+deltaX){
if(board.getAt(newY, i)!=board.INVALID_POSITION){
if(i==newX)
return true;
else
db.persons.insert({name:"Peter",email:"petergriffin@gmail.com",age:42})
@andrefreitas
andrefreitas / hello.py
Created May 6, 2013 16:08
helloWorldQt
import sys
from PyQt4.QtGui import QApplication
from PyQt4.QtDeclarative import QDeclarativeView
from PyQt4.QtCore import QUrl
app = QApplication(sys.argv)
view = QDeclarativeView()
view.setSource(QUrl('hello.qml'))
view.show()
view.setWindowTitle("Hello World")
@andrefreitas
andrefreitas / gist:5562913
Created May 12, 2013 09:11
Exemplo da utilização de Maps em matlab
% Using Maps to have constant time complexity to access data
% See more at http://www.mathworks.com/help/matlab/map-containers.html
% Example here http://stackoverflow.com/questions/3591942/hash-tables-in-matlab
% Let's supose we have the following information:
table =[ [1 , 1 , 1 , 0.444 , 0.67 , 0.98];
[1 , 1 , 2 , 0.254 , 0.67 , 0.98]
];
% So to store them in an efficient way
"""
Teaching a neural network to do the XOR binary operator
Artificial Intelligence - FEUP
"""
from pybrain.tools.shortcuts import buildNetwork
from pybrain.datasets import SupervisedDataSet
from pybrain.supervised.trainers import BackpropTrainer
from pybrain import TanhLayer
""" Builds the network """
<!DOCTYPE html>
<html>
<head>
<title>Olá mundo</title>
<meta charset="UTF-8">
</head>
<body>
Olá mundo
</body>
</html>