Skip to content

Instantly share code, notes, and snippets.

View fmasanori's full-sized avatar

Fernando Masanori fmasanori

View GitHub Profile
@fmasanori
fmasanori / reddit query mongo.py
Last active March 5, 2018 13:01
reddit query mongo
import pymongo
import sys
connection = pymongo.MongoClient("mongodb://localhost")
db = connection.reddit
stories = db.stories
def find():
query = {'title':{'$regex': 'Python'}}
selector = {'title': 1, 'num_comments': 1, '_id': 0}
@fmasanori
fmasanori / query4 mongo.py
Last active March 5, 2018 13:09
query4 mongo
import pymongo
import sys
connection = pymongo.MongoClient("mongodb://localhost")
db = connection.school
scores = db.scores
def find():
query = {}
@fmasanori
fmasanori / find and modify.py
Last active March 5, 2018 13:20
find and modify mongo
import pymongo
def get_next_sequence_number(name):
connection = pymongo.MongoClient("mongodb://localhost")
db = connection.test
counters = db.counters
counter = counters.find_and_modify(query={'type':name},
update={'$inc':{'value':1}},
upsert=True, new=True)
@fmasanori
fmasanori / gridfs mongo.py
Last active March 7, 2018 01:22
gridfs mongo
import pymongo
import gridfs
import sys
con = pymongo.MongoClient("mongodb://localhost")
db = con.test
videos_meta = db.videos_meta
grid = gridfs.GridFS(db, 'videos')
@fmasanori
fmasanori / Oficina MongoDB e Python FISL
Last active February 27, 2025 14:27
Oficina MongoDB e Python FISL
Oficina MongoDB e Python - FISL
Resumo https://university.mongodb.com/courses/M220P/about
Install python 3.x (provavelmente vc já tem, 3.7 no mínimo)
https://www.python.org/downloads/
para testar python -V
Install mongoDB última versão
https://www.mongodb.org/downloads
criar diretório \data\db com as permissões necessárias para testar bin\mongod (servidor)
@fmasanori
fmasanori / adivinha.py
Created July 18, 2013 13:05
Jogo simples em Python 3
from random import randint
print ('Bem vindo!')
sorteado = randint(1, 100)
chute = 0
while chute != sorteado:
chute = int(input ('Chute: '))
if chute == sorteado:
print ('Você venceu!')
else:
if chute > sorteado:
@fmasanori
fmasanori / asteroids.py
Created July 19, 2013 21:02
CodeSkulptor Asteroids
# program template for Spaceship
import simplegui
import math
import random
# globals for user interface
WIDTH = 800
HEIGHT = 600
score = 0
lives = 3
@fmasanori
fmasanori / hacking_bixurras.py
Last active December 23, 2015 12:49
Código Xtreme Go Horse que fiz em 2 minutos para hackear fotos dos calouros da FATEC haha
#conteúdo do texto abaixo original de http://afterfest.com.br/fotos/XV-Edicao
texto = '''
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Fotos BIXURRASCO - XV Edicao - FATEC - 14/09/2013 - Afterfest</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta content="all" name="robots" />
@fmasanori
fmasanori / metaprogramming42.py
Last active June 2, 2020 21:49
42 metaprogramming
from functools import wraps
def hitchhiker(func):
@wraps(func)
def wrapper(*args, **kwargs):
return 42
return wrapper
@hitchhiker
def fat(n):
if n < 2: return 1
@fmasanori
fmasanori / pi.py
Created October 28, 2013 23:18
Cálculo de Pi
def pi_digits(n):
k, a, b, a1, b1 = 2, 4, 1, 12, 4
while n > 0:
p, q, k = k*k, 2*k+1, k+1
a, b, a1, b1 = a1, b1, p*a+q*a1, p*b+q*b1
d, d1 = a/b, a1/b1
while d == d1:
yield int(d)
n -= 1
a, a1 = 10*(a%b), 10*(a1%b1)