Skip to content

Instantly share code, notes, and snippets.

View ooduor's full-sized avatar
🏠
Working from home

Antony Oduor ooduor

🏠
Working from home
View GitHub Profile
@robban
robban / gist:328191
Created March 10, 2010 18:44
Easily add a google map location picker to your form
<!--
Use this snippet to add a google map location chooser to your form
Step 1: Get a google map api key and insert it in the first javascript tag
Step 2: In your html form, create two hidden elements, one for latitude, and one for longitude. Give the elements ids and set the LATITUDE_ELEMENT_ID and LONGITUDE_ELEMENT_ID to the appropriate variables
Done!
-->
@tylerhall
tylerhall / strong-passwords.php
Created August 12, 2010 21:38
A user friendly, strong password generator PHP function.
<?PHP
// Generates a strong password of N length containing at least one lower case letter,
// one uppercase letter, one digit, and one special character. The remaining characters
// in the password are chosen at random from those four sets.
//
// The available characters in each set are user friendly - there are no ambiguous
// characters such as i, l, 1, o, 0, etc. This, coupled with the $add_dashes option,
// makes it much easier for users to manually type or speak their passwords.
//
// Note: the $add_dashes option will increase the length of the password by
@isaacs
isaacs / node-and-npm-in-30-seconds.sh
Last active July 14, 2024 19:27
Use one of these techniques to install node and npm without having to sudo. Discussed in more detail at http://joyeur.com/2010/12/10/installing-node-and-npm/ Note: npm >=0.3 is *safer* when using sudo.
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://www.npmjs.org/install.sh | sh
@reedobrien
reedobrien / recaptcha.py
Created November 16, 2010 04:57
Deform Recaptcha Widget
## widget
import httplib2
from urllib import urlencode
import colander
from colander import null
from colander import Invalid
from deform.widget import CheckedInputWidget
@nrrrdcore
nrrrdcore / inset_input.css
Created August 9, 2012 23:35
The Perfect Inset Input CSS
input {
height: 34px;
width: 100%;
border-radius: 3px;
border: 1px solid transparent;
border-top: none;
border-bottom: 1px solid #DDD;
box-shadow: inset 0 1px 2px rgba(0,0,0,.39), 0 -1px 1px #FFF, 0 1px 0 #FFF;
}
@revolunet
revolunet / mailgun-test.py
Last active September 6, 2022 17:08
create and send a tracked message through the mailgun SMTP gateway
# -*- encoding: UTF-8 -*-
import smtplib
import json
from email.mime.text import MIMEText
MAILGUN_SMTP_LOGIN = "postmaster@revolunet.mailgun.org"
MAILGUN_SMTP_PASSWORD = "secret"
def send_message_via_smtp(from_, to, mime_string):
@kwatch
kwatch / gist:4672421
Last active December 25, 2019 14:51
How to convert query object into non-prepared sql string in SQLAlchemy and psycopg2
def query2sql(query):
"""convert query object into non-prepared sql string in SQLAlchemy and psycopg2"""
compiler = query.statement.compile()
params = compiler.params
prepared_sql = compiler.string # or str(compiler)
psycopg2_cursor = query.session.connection().connection.cursor()
sql = psycopg2_cursor.mogrify(prepared_sql, params)
return sql
@utek
utek / Exclude_tables.md
Last active June 6, 2024 08:11
Define ignored tables in alembic.ini

Add this in your ini file:

[alembic:exclude]
tables = spatial_ref_sys

In env.py:

    import re 
    
@hest
hest / gist:8798884
Created February 4, 2014 06:08
Fast SQLAlchemy counting (avoid query.count() subquery)
def get_count(q):
count_q = q.statement.with_only_columns([func.count()]).order_by(None)
count = q.session.execute(count_q).scalar()
return count
q = session.query(TestModel).filter(...).order_by(...)
# Slow: SELECT COUNT(*) FROM (SELECT ... FROM TestModel WHERE ...) ...
print q.count()
@jmatthias
jmatthias / uuid_column.py
Created February 27, 2014 23:48
Database-agnostic SQLAlchemy UUID column type
import psycopg2.extras
import sqlalchemy.dialects.postgresql
from sqlalchemy.types import TypeEngine
from sqlalchemy.types import String
from sqlalchemy.types import TypeDecorator
import uuid
# Required for PostgreSQL to accept UUID type.
psycopg2.extras.register_uuid()