Skip to content

Instantly share code, notes, and snippets.

def get_last_lines(fp, num, step=10):
pos = step
lines = []
quit = False
while len(lines) < num + 1 and not quit:
fp.seek(-pos, 2)
if int(fp.tell()) == 0:
quit = True
lines = fp.readlines()
@maio
maio / ftest.py
Created September 3, 2009 12:34 — forked from dizzi/gist:180271
import ftplib
import sys
import os
ftpServer = 'xxx'
ftpUser = 'xx'
ftpPass = 'xx'
#ftpPath = 'FileFlowStatus/'
ftpPath = '/'
// outlets
IBOutlet UILabel *label;
// actions
- (IBAction)onChange:(id)sender;
// storage
[[NSUserDefaults standardUserDefaults] storeFloat: 123 forKey: @"key"];
float value = [[NSUserDefaults standardUserDefaults] floatForKey: @"key"];
@maio
maio / .vimrc
Created November 7, 2010 19:42
Vim + Xcode
set errorformat=%f:%l:\ error:\ %m,%f:%l:\ warning:\ %m
set autowrite
au! BufWritePost *.m make! test
<?php
final class AddController {
public function __construct() {
require 'model/WriteModel.php';
}
public function newPost($name,$text) {
$addModel = new WriteModel($name, $text);
return $addModel;
@maio
maio / 1. install PHPUnit
Created June 2, 2011 16:41
First Test in PHPUnit
# Run these commands to install PHPUnit
# More info @ http://www.phpunit.de/manual/current/en/installation.html
pear channel-discover pear.phpunit.de
pear channel-discover components.ez.no
pear channel-discover pear.symfony-project.com
pear install phpunit/PHPUnit
# OSX - you may need to upgrade pear before installing PHPUnit
use Test::More;
use Module;
is($Module::data, undef);
$Module::data = 10;
done_testing();
@maio
maio / tests.java
Created July 18, 2011 20:23
Re: Pětiminutové intro do Mockito knihovny
public void testGetTotalPriceReturnsSumOfAllItemsPrices() {
basket.addItem(new Item(1));
basket.addItem(new Item(2));
assertThat(basket.getTotalPrice(), is(3));
}
public void testClearMakesBasketEmpty() {
basket.addItem(new Item());
basket.clear();
@maio
maio / Expect.t
Created August 9, 2011 21:34
Jasmine matchers clone in Perl
# Perl clone of:
# https://github.com/pivotal/jasmine/wiki/Matchers
# https://github.com/pivotal/jasmine/wiki
use Test::Spec;
# usage
describe 'Expect' => sub {
describe 'implementing matcher' => sub {
it toEqual => sub {
@maio
maio / ipaste.vim
Created August 17, 2011 21:03
Detect correct indentation for pasted text. Helps when moving code around.
nmap P :call <SID>pasteAbove()<CR>
nmap p :call <SID>pasteBelow()<CR>
fun! s:pasteAbove()
let indentDiff = s:detectIndentDiff("O")
exe "norm! P"
call s:fixPasteIndent(indentDiff)
endfun
fun! s:pasteBelow()