Skip to content

Instantly share code, notes, and snippets.

@pithyless
pithyless / Model_and_Form_Validations.md
Created September 13, 2011 22:49
Django Field Notes

Model + Form validations

Some of Django's choices on how to handle data integrity are wrong, or at the very least, unexpected to the uninitiated developers. I'm not here to pass judgement; like many people, I'd just like to get back to doing real work. Some notes on how to stay safe in Django:

What should I know?

  • Django now has both Form validations and Model validations
  • Django used to only have Form validations
  • Form’s is_valid() performs model validation automatically
  • full_clean() is never actually called by Django (see ticket #13100)
@colindensem
colindensem / README
Created September 22, 2011 22:09
ChicagoBoss Admin install Notes
This is a config guide to add the cb_admin to a sample application.
https://github.com/evanmiller/chicagoboss_admin
The dir structure is thus:
~/erlang/
~/erlang/ChicagoBoss
~/erlang/cb_admin
~/erlang/mynewproject
@gnunicorn
gnunicorn / forms.html
Created October 13, 2011 16:02
Jinja2 WTForms macros for twitter bootstrap
{%- macro form_field_label(field) -%}
<label for="{{ field.id }}">{{ field.label.text }}
{%- if field.flags.required -%}
<abbr title="Diese Feld muss angegeben werden">*</abbr>
{%- endif %}</label>
{% endmacro %}
{%- macro form_field_description(field) -%}
{% if field.description %}
<span class="descr">{{ field.description }}</span>
@rduplain
rduplain / app.py
Created November 10, 2011 15:44
Customize Flask to select a template based on some criteria.
"Customize Flask to select a template based on some criteria."
import os
from flask import Flask, request, render_template
from flask.helpers import locked_cached_property
from jinja2 import FileSystemLoader, TemplateNotFound
# Import a detection utility from your project, not defined here.
# Takes a request object and returns True if browser is mobile.
@jboner
jboner / latency.txt
Last active July 25, 2024 11:30
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@solar
solar / install.sh
Created October 16, 2012 10:47
install redis with supervisord
#!/bin/sh
version="2.6.3"
priority="20603"
sudo mkdir -p /var/redis /var/log/redis
curl -sL http://redis.googlecode.com/files/redis-${version}.tar.gz | tar zx
cd redis-${version}/
make
sudo make PREFIX=/usr/local/redis/${version} install
@ruslander
ruslander / mailgun.erl
Last active August 24, 2016 20:14
Update the api key to reflect your account
%curl -s --user 'api:key-8av0ox9abrs2icvagny' \
% https://api.mailgun.net/v2/bang.mailgun.org/messages \
% -F from='Excited User <postmaster@bang.mailgun.org>' \
% -F to=masquerade2ruslan@gmail.com \
% -F subject='Hello' \
% -F text='Testing some Mailgun awesomness!'
-module(mailgun).
-compile(export_all).
@xeoncross
xeoncross / ajax.js
Last active August 3, 2023 06:06
Simple, cross-browser Javascript POST/GET xhr request object. Supports request data and proper AJAX headers.
/**
* IE 5.5+, Firefox, Opera, Chrome, Safari XHR object
*
* @param string url
* @param object callback
* @param mixed data
* @param null x
*/
function ajax(url, callback, data, x) {
try {
@takeshixx
takeshixx / hb-test.py
Last active July 4, 2024 03:29
OpenSSL heartbeat PoC with STARTTLS support.
#!/usr/bin/env python2
"""
Author: takeshix <takeshix@adversec.com>
PoC code for CVE-2014-0160. Original PoC by Jared Stafford (jspenguin@jspenguin.org).
Supportes all versions of TLS and has STARTTLS support for SMTP,POP3,IMAP,FTP and XMPP.
"""
import sys,struct,socket
from argparse import ArgumentParser
@bryanhunter
bryanhunter / build-erlang-17.0.sh
Last active May 22, 2022 12:02
Build Erlang 17.0 on a fresh Ubuntu box (tested on 12.04 and 14.04)
#!/bin/bash
# Pull this file down, make it executable and run it with sudo
# wget https://gist.githubusercontent.com/bryanhunter/10380945/raw/build-erlang-17.0.sh
# chmod u+x build-erlang-17.0.sh
# sudo ./build-erlang-17.0.sh
if [ $(id -u) != "0" ]; then
echo "You must be the superuser to run this script" >&2
exit 1
fi