Skip to content

Instantly share code, notes, and snippets.

<?php
class Model{
protected $id = null;
public function setId($id){
$this->id = $id;
}
public function getId(){
return $this->id;
}
}
@andreyp
andreyp / gist:1084193
Created July 15, 2011 06:23
screenshot with selenium
#!/usr/bin/env python
from selenium import webdriver
browser = webdriver.Firefox()
browser.get('http://lenta.ru/')
browser.save_screenshot('screenie.png')
browser.close()
@andreyp
andreyp / fake_sendmail.sh
Created August 5, 2011 08:02
Fake Sendmail for testing
#!/bin/sh
prefix="/tmp/mail/sendmail/new"
numPath="/tmp/mail/sendmail"
if [ ! -f $numPath/num ]; then
echo "0" > $numPath/num
fi
num=`cat $numPath/num`
num=$(($num + 1))
echo $num > $numPath/num
@andreyp
andreyp / change_current.sh
Created September 22, 2011 11:02
For quick change root_dir without change webserver config
#! /bin/sh
CURRENT_DIR=/home/andrey/projects/current
PROJECT_DIR=/home/andrey/projects
PROJECT=$1
DIR=$2
rm $CURRENT_DIR/$PROJECT
ln -s $PROJECT_DIR/$DIR $CURRENT_DIR/$PROJEC
@andreyp
andreyp / gist:1350792
Created November 9, 2011 08:01
count tags in xml files
ls -lah | grep %filename%*.xml | awk '{print $9}' | xargs grep -c '%close tag%' | awk '{i = split($0,a,":"); print a['2']}' | awk '{s+=$1}END{print s}'
@andreyp
andreyp / gist:2519651
Created April 28, 2012 14:54
virtualenv activate for deianization
VIRTUAL_ENV="$(cd "$(dirname "${BASH_SOURCE:-0}")/.."; pwd)"
from struct import pack, unpack, calcsize
import cStringIO
def sphinx_unpack(fmt, fp):
return unpack(fmt, fp.read(calcsize(fmt)))
def parse_query_result(data, query_count):
data = cStringIO.StringIO(data)
result = []
@andreyp
andreyp / blog_mapper.php
Created September 27, 2012 14:03
data mapper
<?php
class BlogMapper extends AbstractMapper
{
protected $tableName = 'blog';
protected $fieldIdName = 'blog_id';
public function FindByName ($name)
{
$sql = sprintf('SELECT * FROM `blog` WHERE `blog_name` =%s LIMIT 1', $this->db->quot($name));
$row = $this->db->sqlparse($sql);
return ($row) ? $this->CreateFromRow($row[0]) : false;
from operator import mul
x = [1,2,4,0,5,0]
x_mul = reduce(mul, [ y for y in x if y])
count_nil = x.count(0)
if count_nil == 1:
print [ (0 if y != 0 else x_mul) for y in x]
elif count_nil >= 2:
# base
set -g set-titles on
set -g set-titles-string "#H > #W"
# automatically set window title
setw -g automatic-rename
set -g base-index 1
set -g history-limit 5000