Skip to content

Instantly share code, notes, and snippets.

import urllib.request
import json
resp = urllib.request.urlopen('http://worldcup.sfg.io/matches').read()
for jogo in json.loads(resp.decode('utf-8')):
if jogo['status'] == 'completed':
print (jogo['home_team']['country'], jogo['home_team']['goals'], 'x', jogo['away_team']['country'], jogo['away_team']['goals'])
def horner(p, x):
'''Evalúa p(x) y p'(x), donde el polinomio p está representado como una
lista donde cada p[k] es el coeficiente de x**k'''
r, d = 0, 0
for k in range(len(p) - 1, 0, -1):
r = x*r + p[k]
d = x*d + k*p[k]
return x*r + p[0], d
def newton(p, x, eps):
#usr/bin/python
#coding: utf-8
#Cdt.py
from math import *
#resolveremos una ecuacion cuadratica de la forma ax^2+bx+c=0
class Cdt(object):
def __init__(self, cc, cx, ti): #cc=a, cx=b y ti=c
self.a1=cc
@Ismael-VC
Ismael-VC / sexpr.jl
Last active August 29, 2015 14:12 — forked from toivoh/sexpr.jl
# ---- @sexpr: S-expression to AST conversion ----
is_expr(ex, head::Symbol) = (isa(ex, Expr) && (ex.head == head))
is_expr(ex, head::Symbol, n::Int) = is_expr(ex, head) && length(ex.args) == n
macro sexpr(ex)
esc(sexpr_to_expr(ex))
end
sexpr_to_expr(ex) = expr(:quote, ex)
import socket
import fcntl
import struct
def getHwAddr(ifname):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
info = fcntl.ioctl(s.fileno(), 0x8927, struct.pack('256s', ifname[:15]))
return ''.join(['%02x:' % ord(char) for char in info[18:24]])[:-1]
@Ismael-VC
Ismael-VC / newton.jl
Last active August 29, 2015 14:14 — forked from mlubin/newton.jl
function squareroot(x)
it = x
while abs(it*it - x) > 1e-13
it = it - (it*it-x)/(2it)
end
return it
end
function time_sqrt(x)
const num_iter = 100000

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@Ismael-VC
Ismael-VC / caminos.py
Last active August 29, 2015 14:17 — forked from knkillname/caminos.py
## Algoritmos de caminos más cortos
from estructuras import Cola, ColaMin
from conectividad import ordenamiento_topologico
inf = float('inf') #Tratar infinito como un numero
def recorrido_a_lo_ancho(G, s):
dist, padre = {v:inf for v in G}, {v:v for v in G}
dist[s] = 0
@Ismael-VC
Ismael-VC / 0_reuse_code.js
Last active August 29, 2015 14:17
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@Ismael-VC
Ismael-VC / sieve.jl
Last active August 29, 2015 14:23 — forked from narenaryan/sieve.jl
# Sieve of Eratosthenes, docstrings coming in Julia 0.4
function es(n::Int64) # accepts one 64 bit integer argument
isprime = ones(Bool, n) # n-element vector of true-s
isprime[1] = false # 1 is not a prime
for i in 2:int64(sqrt(n)) # loop integers from 2 to sqrt(n), explicit conversion to integer
if isprime[i] # conditional evaluation
for j in (i*i):i:n # sequence from i^2 to n with step i
isprime[j] = false # j is divisible by i
end
end