Skip to content

Instantly share code, notes, and snippets.

View flaviocdc's full-sized avatar

Flávio Coutinho da Costa flaviocdc

  • Microsoft
  • Greater Seattle Area
  • 04:55 (UTC -07:00)
View GitHub Profile
@flaviocdc
flaviocdc / FinallyExample.java
Created November 10, 2014 20:00
Finally Example
public class FinallyExample {
public static void main(String[] args) {
System.out.println(foo("1"));
System.out.println(foo("a"));
}
public static int foo(String numStr) {
try {
int x = Integer.parseInt(numStr);
@flaviocdc
flaviocdc / plane_tickets.py
Created February 24, 2014 03:01
TalentBuddy Plane Tickets - too slow!
from bisect import bisect_left
def index(a, x):
'Locate the leftmost value exactly equal to x'
i = bisect_left(a, x)
if i != len(a) and a[i] == x:
return i
raise ValueError
def get_journey(departure_ids, destination_ids):
@flaviocdc
flaviocdc / tuple_sum.py
Created February 23, 2014 01:48
TalentBuddy.co Tuple Sum using DFS
def tuple_sum(a, s):
ret = backtrack(a, s, 0, 1, 2, 3)
print ' '.join(str(i) for i in ret)
def backtrack(a, s, x, y, w, z):
result = a[x] + a[y] + a[w] + a[z]
conj = set([x, y, w, z])
if result == s and len(conj) == 4:
@flaviocdc
flaviocdc / firewall.py
Created January 31, 2014 14:25
Working IPTables NAT QEMU hook
#!/usr/bin/env python
import sys
import os
import errno
from time import sleep
FIFO_PATH = "/etc/scripts/ipc"
MESSAGE="libvirtd-restart\n"
SLEEP_SECS=2
@flaviocdc
flaviocdc / przombie.c
Last active December 30, 2015 06:09
Trabalho 5 de SO2
#include <sys/types.h>
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/stat.h>
#include <string.h>
#include <stdbool.h>
#include <unistd.h>
#include <signal.h>
package com.brauto.automacao.device.usb;
import android.app.Service;
import android.content.Intent;
import android.os.Handler;
import android.os.IBinder;
import android.util.Log;
import com.brauto.automacao.MyApp;
import com.googlecode.androidannotations.annotations.EService;
int led = 13;
int incomingByte = 0;
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
pinMode(led, OUTPUT);
}
Index: src/test/br/ufrj/gnosys/framework/mock/FakeLogin.java
===================================================================
--- src/test/br/ufrj/gnosys/framework/mock/FakeLogin.java (revision 3079)
+++ src/test/br/ufrj/gnosys/framework/mock/FakeLogin.java (working copy)
@@ -1,15 +1,23 @@
package br.ufrj.gnosys.framework.mock;
+import java.util.HashSet;
+
+import javax.persistence.EntityManager;
@flaviocdc
flaviocdc / palavras-lidas-v1.py
Created September 23, 2013 03:40
Palavras Lidas
pop=list(raw_input("digite uma palavra: "))
print len(pop),"numero de caracteres da palvra"
print pop[0],"e a primeira letra da plavra"
print pop[-1],"e a ultima letra da palavra"
for i in range(len(pop)):
caracter = pop[i]
if caracter == 'a' or caracter == 'e' or caracter == 'i' or caracter == 'o' or caracter == 'u':
pop[i] = ' '
@flaviocdc
flaviocdc / markov.py
Last active December 19, 2015 13:39
Questao 4 - Lista 8
import numpy as np
# matriz de transicoes
P = np.array([[0.0, 1.0/3, 1.0/3, 1.0/3], [0.0, 0.0, 0.0, 1.0], [1.0/2, 0.0, 0.0, 1.0/2], [0.0, 0.0, 1.0, 0.0]])
def sistema_linear():
# declarando matriz original
A_original = np.array([[1.0,-(1.0/2),0.0,0.0], [-1.0/3,1.0,0.0,0.0], [-1.0/3,0.0,1.0,-1.0], [-1.0/3, -1.0, -1.0/2, 1.0]])
# substituindo a primeira linha por [1, 1, 1, 1] para podermos resolver o sistema