Skip to content

Instantly share code, notes, and snippets.

<?php
public function resize($new_w, $new_h, $preserve=false){
$name = $this->image;
$e = $this->getExtension();
$filename = dirname($this->image) .'/'. $e['file'] .'_'. $new_w .'x'. $new_h . $e['extension'];
// this function only works if the imagecreatefromjpeg function exists
if(!function_exists('imagecreatefromjpeg')){ return false; }
// adapted from http://icant.co.uk/articles/phpthumbnails/
<?php
class A {
public $id;
public function __construct($id){
$this->id = $id;
}
}
find . -name ._* -not -path *.svn* -exec svn rm {} \;
params = {
:font_size => 10
}
# 1
defaults = {
:font => "Times-Roman",
:font_size => 11,
:stroke => false
}
#!/usr/bin/env python
"""
Create a new function based on the current line
Examples:
Line: myFunction
Output: a function with the name myFunction
from django.conf import settings
from django.utils.http import urlquote
from django import http
class EnforceHostnameMiddleware(object):
"""
Enforce the hostname per the ENFORCE_HOSTNAME setting in the project's settings
The ENFORCE_HOSTNAME can either be a single host or a list of acceptable hosts
"""
// jQuery plugin
// make "blank" options non-selectable
(function($){
$(document).ready(function(){
jQuery('select').change(function(){
var select = jQuery(this)
var blankValues = ['', '-', '#', ' ']
if(jQuery.inArray(select.val(), blankValues) != -1){
jQuery('option:selected', select).attr('selected', '')
jQuery('option:first', select).attr('selected', 'selected')
<?php
// convert the error reporting value to an array of constant values
// from: http://php.net/manual/en/function.error-reporting.php
$bit = ini_get('error_reporting');
$res = array();
while ($bit > 0) {
for($i = 0, $n = 0; $i <= $bit; $i = 1 * pow(2, $n), $n++) {
$end = $i;
}
$res[] = $end;
import datettime
import rotatelib
import MySQLdb
db = MySQLdb.connect('localhost', 'user', 'password', 'my_database')
# find any backup tables (tables with a date in the name) that are older than 5 days
items = rotatelib.list_backup_tables(db=db, before=datetime.timedelta(5))
for item in items:
#!/usr/bin/env ruby
#
# Textmate item to increment all numbers in a selection
#
# If you have:
#
# line1
# line1
# line1