Skip to content

Instantly share code, notes, and snippets.

View omaraboumrad's full-sized avatar

Omar Abou Mrad omaraboumrad

View GitHub Profile
@omaraboumrad
omaraboumrad / index.html
Last active August 29, 2015 13:56
d3 build form dynamically
<!doctype html>
<html>
<head>
<title>Sup</title>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script type="text/javascript">
window.onload = function(){
var schema = {
fields: [
{name: 'first_name', type: 'text', display: 'First Name'},
@omaraboumrad
omaraboumrad / index.html
Created February 21, 2014 12:19
d3 consume api and build document
<!doctype html>
<html>
<head>
<title>Reddit JSON</title>
<style>
body{ background-color: #C6C6C6; }
#content div {
border: 1px solid #000000;
margin: 5px;
padding: 5px;
@omaraboumrad
omaraboumrad / main.lua
Last active August 29, 2015 14:08
Pixel clone of Flappy bird using Love2d
function love.load()
reset()
topscore = 0
local font = love.graphics.newFont(24)
love.graphics.setFont(font)
end
function reset()
x = 60
y = love.window.getHeight()/2
@omaraboumrad
omaraboumrad / chat.html
Created February 16, 2015 14:28
Experimenting with websocketd
<!DOCTYPE html>
<html>
<head>
<title>Chat!</title>
<style>
</style>
</head>
<body>
<ul id="messages"></ul>
@omaraboumrad
omaraboumrad / astlookup.py
Last active October 9, 2015 08:11
Run static checks through various ast paths
import sys
import ast
is_if = lambda s: isinstance(s, ast.If)
is_for = lambda s: isinstance(s, ast.For)
is_call = lambda s: isinstance(s, ast.Call)
call_name_is = lambda s, n: is_call(s) and hasattr(s.func, 'attr') and s.func.attr == n
has_else = lambda s: is_if(s) and len(s.orelse) > 0
is_return = lambda s: isinstance(s, ast.Return)
is_name = lambda s: isinstance(s, ast.Name)
@omaraboumrad
omaraboumrad / test.py
Created November 12, 2012 23:11
lists files based on requested path (wsgiref playground)
import os
from wsgiref import simple_server
def format_html(entries):
html = """<html><body><ul>%s</ul></body></html"""
return html % entries
def format_entries(requested_dir, children):
result = []
a = '<li><a href="%s">%s</a></li>'
@omaraboumrad
omaraboumrad / foldtext.vim
Created November 5, 2015 08:09
light vim fold text
" class Foo(Bar): │
" └── [ 13 ] ────•
set fillchars="fold: "
setlocal foldtext=ManualFillCharText()
function! ManualFillCharText()
" TODO: make it support the tabs/spaces/different width
let total = (v:foldend - v:foldstart)
@omaraboumrad
omaraboumrad / .inputrc
Last active November 17, 2015 10:11
Enable reverse search in OSX's default python
bind "^R" em-inc-search-prev
@omaraboumrad
omaraboumrad / contracts.py
Created April 24, 2014 09:54
poor man's contracts
class Entity(object):
def __init__(self, name):
self.name = name
class Powered(object):
def is_on(self):
return self.state == 'on'
class Machine(Entity, Powered):
def __init__(self, name, state):
@omaraboumrad
omaraboumrad / processor.py
Created December 20, 2012 08:20
Django context processor
# in processor.py
def site_processor(request):
return {'Foo': 'Bar'}
# in settings.py
from django.conf import global_settings as DEFAULT_SETTINGS
TEMPLATE_CONTEXT_PROCESSORS = DEFAULT_SETTINGS.TEMPLATE_CONTEXT_PROCESSORS + (
'myapp.processor.site_processor',
)