Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Marcin Kitowicz kitek

🏠
Working from home
View GitHub Profile
View Lista ToDo.md

Moja lista:

  • zadanie pierwsze
  • zadanie drugie
@kitek
kitek / gist:1388261
Created Nov 23, 2011
Prosty parser linków
View gist:1388261
<?
// Bardzo prosty parser linków
$html = preg_replace(
'#(([^ \'\"\<]+)?[^ \'\"\.\<]+\.(pl|com|net|org)(\/[^ \'\"\<]+)?)#',
'<a href="http://$1" target="_blank" rel="nofollow">$1</a>',
$html
);
@kitek
kitek / gist:1388195
Created Nov 23, 2011
jQuery.post i dodatkowe parametry
View gist:1388195
var doSomething = function(extraStuff) {
return function(data, textStatus) {
//do something with extraStuff
};
};
var clicked = function() {
var extraStuff = { myParam1: 'foo', myParam2: 'bar' };
$.post("someurl.php", someData, doSomething(extraStuff), "json");
};
@kitek
kitek / gist:1388267
Created Nov 23, 2011
Generator losowej godziny
View gist:1388267
<?
// Prosty generator losowej godziny
function getRandomHour() {
$godzina = str_pad(rand(6,23), 2, "0", STR_PAD_LEFT);
$minuta = str_pad(rand(0,59), 2, "0", STR_PAD_LEFT);
$sekunda = str_pad(rand(0,59), 2, "0", STR_PAD_LEFT);
return $godzina .':'. $minuta .':'. $sekunda;
}
@kitek
kitek / gist:1388299
Created Nov 23, 2011
Generator losowych adresów email
View gist:1388299
<?
$emails = array();
function getRandomEmail() {
global $emails;
if (empty($emails)) {
$f = file_get_contents('http://ktmatu.com/cgi-bin/rea.pl');
preg_match_all('/\=\"mailto\:(.*)\"/', $f, $matches);
$emails = $matches[1];
@kitek
kitek / gist:1392334
Created Nov 24, 2011
Short if in Python
View gist:1392334
# Short if in Python
usersOnline = p.count() - 1 if p.count() > 0 else 0
@kitek
kitek / gist:1392242
Created Nov 24, 2011
Zliczanie elementów w GAE
View gist:1392242
from botModels import Roster, PresenceStatus
import logging as console
# Zliczanie elementów w GAE
# SELECT count(1) FROM PresenceStatus WHERE online = True
p = PresenceStatus.all(keys_only=True)
p.filter("online =",True)
items = p.count()
console.info(items)
@kitek
kitek / gist:1392254
Created Nov 24, 2011
Szukanie po kluczu w GAE
View gist:1392254
# Szukanie po kluczu w GAE
p = PresenceStatus.get_by_key_name(jid)
console.info(p.online)
@kitek
kitek / gist:1397814
Created Nov 27, 2011
GAE NamedModel - własny klucz w modelu
View gist:1397814
class NamedModel(db.Model):
"""A Model subclass for entities which automatically generate their own key
names on creation. See documentation for _generate_key function for
requirements."""
def __init__(self, *args, **kwargs):
kwargs['key_name'] = _generate_key(self, kwargs)
super(NamedModel, self).__init__(*args, **kwargs)
def _generate_key(entity, kwargs):
"""Generates a key name for the given entity, which was constructed with
@kitek
kitek / gist:1400187
Created Nov 28, 2011
NODE.JS Wysyłanie HTTP POST
View gist:1400187
var http = require('http');
exports.sendPost = function(options,data,callback) {
var post_data = querystring.stringify(data);
var opts = {
host: options.host,
port: options.port,
maxSockets : 100,
path: options.path,
method: 'POST',