Skip to content

Instantly share code, notes, and snippets.

@buriy
buriy / index.php
Created June 12, 2009 16:07
convert page to iphone-compatible format
<!-- Sample usage: http://localhost/convert/gist.github.com/gists/128733 -->
<!-- Hardcoded charset bug to be sorted out yet -->
<?php $f = file("http://".$_SERVER['QUERY_STRING']); ?>
<?php header("Content-type: text/html; charset=cp1251"); ?>
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;">
<style> body { width: 320px !important; } nobr {white-space: normal !important; } dd { margin: 5px 10px;} </style>
<?php echo implode($f, "") ?>
@buriy
buriy / duration.py
Created May 25, 2009 00:13
Django DurationField
from widgets.duration import DurationField as FDurationField
from widgets.duration import TimeDelta
from django.db.models.fields import Field
from django.core.exceptions import ValidationError
from django.db import connection
class DurationProxy(object):
def __init__(self, field):
self.field_name = field.name
<?
$domain = GetHostByName($REMOTE_ADDR);
if($_POST[submit1])
{
$f="INSERT INTO vote SET id_img='".$_POST['img1']."',rating='".$_POST['num']."',ipname='$domain'";
$row=mysql_query($f);
}
else { echo "<b>click on vote!</b> or go back to <A HREF=http://agh.ge/form/vote/index.php>home page</A>";}
class SendExceptionMiddleware(object):
def process_exception(self, request, exception):
"""
Load exceptions into CrashKit
Credits to wiz
http://djangosnippets.org/snippets/1483/
"""
try:
env = {}
# from py2.6 distr
# -*- coding: utf-8 -*-
"""
ast
~~~
The `ast` module helps Python applications to process trees of the Python
abstract syntax grammar. The abstract syntax itself might change with
each Python release; this module helps to find out programmatically what
@buriy
buriy / gist:99257
Created April 21, 2009 17:25
blackjack.py
from random import *
from math import *
#GLOBAL VARIABLES
cards = range(0,52)
def randRange(in_lower, in_upper):
temp_range = in_upper - in_lower
return int(round((temp_range+0.5)*random() + (in_lower - 0.5)))