Skip to content

Instantly share code, notes, and snippets.

Avatar
Living life

Brice Leroy debrice

Living life
View GitHub Profile
@debrice
debrice / loreming.py
Created Nov 26, 2012
I recently wanted to generate data for a project I'm working on. Lorem ipsum offers a package but I really think it is "oversized" for what I needed: generating random text content that looks human.
View loreming.py
import random
def paragraph(min=1, max=20):
def sentence():
nouns = ["time", "person", "year", "way", "day", "thing", "man", "world",
"life", "hand", "part", "child", "eye", "woman", "place", "work", "week",
"case", "point", "government", "company", "number", "group", "problem", "fact"]
verbs = ["be", "have", "do", "say", "get", "make", "go", "know", "take",
"see", "come", "think", "look", "want", "give", "use", "find", "tell", "ask",
"work", "seem", "feel", "try", "leave", "call"]
@debrice
debrice / name_generator.py
Created Nov 26, 2012
I give you a random name generator using the most common american first names (male and female) and last name.
View name_generator.py
import random
FIRST_NAMES = 'James', 'John', 'Robert', 'Michael', 'William', 'David',
'Richard', 'Charles', 'Joseph', 'Thomas', 'Christopher', 'Daniel', 'Paul',
'Mark', 'Donald', 'George', 'Kenneth', 'Steven', 'Edward', 'Brian',
'Ronald', 'Anthony', 'Kevin', 'Jason', 'Matthew', 'Gary', 'Timothy',
'Jose', 'Larry', 'Jeffrey', 'Frank', 'Scott', 'Eric', 'Stephen', 'Andrew',
'Raymond', 'Gregory', 'Joshua', 'Jerry', 'Dennis', 'Walter', 'Patrick',
'Peter', 'Harold', 'Douglas', 'Henry', 'Carl', 'Arthur', 'Ryan', 'Roger',
'Joe', 'Juan', 'Jack', 'Albert', 'Jonathan', 'Justin', 'Terry', 'Gerald',
@debrice
debrice / event_models.py
Created Nov 28, 2012
A solution I use on my flask project to store event related to any generic object to be later displayed on a feed.
View event_models.py
from datetime import datetime
from sqlalchemy.ext.declarative import declared_attr
from sqlalchemy.ext.associationproxy import association_proxy
from sqlalchemy import event
from app import db
class EventAssociation(db.Model):
__tablename__ = "events_association"
@debrice
debrice / equal.js
Last active Oct 13, 2015
A javascript function to compare (by inference) object, strings, number
View equal.js
// test that every value of A exists in B and are equal
// true equality: eq(a,b,1)
// true: eq({b:[1,2]}, {a:1, b:[1,2]})
// false: eq({a:1, b:[1,2]},{b:[1,2]})
// false: eq({b:[1,2]}, {a:1, b:[1,2,3]})
// false: eq({b:[1,2,3]}, {a:1, b:[1,2]})
function eq(a, b, bidirectional){
if (typeof(a) != typeof(b)) return false;
if (typeof(a) in {string: 1, number: 1}) return a == b;
if (a.length != b.length) return false;
View palindrome.py
#!/usr/bin/python
from __future__ import with_statement
# To run:
#
# python -m timeit -n5 -s 'from palindrome import run, get_words, palindrome_X; words = get_words()' 'run(words, palindrome_X)'
def palindrome_1(x):
# 998ms / loop (Best of 3)
return x == ''.join(reversed(x))
View LICENSE.txt
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Jed Schmidt <http://jed.is>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@debrice
debrice / elevators.py
Last active Jul 28, 2016
Optimize the elevator controller
View elevators.py
"""
Elevator Exercise.
Edit the ElevatorController implementation, focusing on
the ElevatorController.call(Passenger) method.
Run the elevator script try to increase your score.
python elevators.py
> score: 51
View config.js
function CSS_compute_middleware(css, next) {
if(this.foo === 'bar'){
css.padding = 0;
}
return next(css)
}
function CSS_async_compute_middleware(css, next) {
if(this.bar === 'foo'){
@debrice
debrice / README.md
Last active Dec 11, 2016
Celery task bug in a SQLAlchemy event
View README.md

Celery Bug

When running a celery task, in a SQLAlchemy event, in a unit-test the connection get destroyed somehow.

I attached the requirement to reproduce the bug:

git clone https://gist.github.com/5762792fc1d628843697.git
cd 5762792fc1d628843697
virtualenv venv
. venv/bin/activate
@debrice
debrice / __init__.py
Created Nov 20, 2012
Here is my way of having fixture loaded within my unit-test. the data from the fixture will then be loaded in your DB instance and also available on the object through self.data
View __init__.py
from flask import Flask, render_template
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.login import LoginManager
# Database
db = SQLAlchemy()
def create_app(config="config"):
# Init app and load config
app = Flask(__name__)