This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
// Proste sortowanie tablicy wielowymiarowej w obiekcie | |
// (w tym przypadku sortujemy malejąco po wymiarze 'similar') | |
class klasa { | |
public sortuj() { | |
usort($tablicaDoSortowania, array('klasa','compare')); | |
} | |
public function compare($a, $b) { | |
if ($a['similar'] == $b['similar']) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
// Bardzo prosty parser linków | |
$html = preg_replace( | |
'#(([^ \'\"\<]+)?[^ \'\"\.\<]+\.(pl|com|net|org)(\/[^ \'\"\<]+)?)#', | |
'<a href="http://$1" target="_blank" rel="nofollow">$1</a>', | |
$html | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
// 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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
$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]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Szukanie po kluczu w GAE | |
p = PresenceStatus.get_by_key_name(jid) | |
console.info(p.online) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Short if in Python | |
usersOnline = p.count() - 1 if p.count() > 0 else 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', |
OlderNewer