Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View hipertracker's full-sized avatar

Jaroslaw Zabiello hipertracker

View GitHub Profile
<?php
# PHP does not recognize long int.
# It recognize only signed int32.
var_dump(is_float(pow(2,30))); # false
var_dump(is_float(pow(2,31))); # true (sic!)
# Even if PHP keep long int internaly as floats,
# it displays them in inconsistent way:
<?php
# What is more readible?
# version 1:
$args[] = '"'.mysql_escape_string(preg_replace("/^'(\d+)$/", '$1', $arg)).'"';
# version 2:
@hipertracker
hipertracker / gist:46021
Created January 12, 2009 15:47
Benchmark (Tak) - response
Response for http://tempe.st/2007/05/the-battle-of-the-languages-part-ii/comment-page-1
Platform: MacPro 2 x Xeon 2.8GHz, MAac OS-X 10.6.2, Java 1.6.0_17
Lua 5.1.4 = 1.89 s.
JRuby 1.4 (--fast --server) = 4.53 s.
Python 2.6.4 = 5.61 s.
Python 3.1 = 6.15 s.
MacRuby 0.5 = 6.62 s.
Ruby 1.9.1p373 = 10.37 s.
<?php
class Source {}
class DbSource extends Source {
function __construct($cfg) {
$this->conn = new PDO($cfg['adapter'].":dbname=".$cfg['db'].";host=".$cfg['host'], $cfg['user'], $cfg['password']);
}
// Mapping properties - db_columns
private function property_names() {
$result = array();
@hipertracker
hipertracker / Benchmark - Fibonacci sequence
Created January 26, 2009 16:04
benchmark - Fibonacci sequence
MacBook Pro, Core Duo 2, 2.8GHz
Mac OS-X 10.6.5
$ cat fib.rb
def fib(n)
return n if n <= 1
fib(n - 1) + fib(n - 2)
end
require "benchmark"
Benchmark.bm do |make|
Złożoność jezyka
Ansi C: http://flickr.com/photos/nicksieger/281055530/
Ruby: http://flickr.com/photos/nicksieger/280661836/in/photostream/
Python: http://flickr.com/photos/nicksieger/281055485/
JavaScript: http://flickr.com/photos/nicksieger/280662871/in/photostream/
Java: http://flickr.com/photos/nicksieger/280662707/in/photostream/
Diassemblacja kodu
# z wątku http://www.rubyonrails.pl/forum/t112-Zamiana-pojedynczych-znakow
require 'iconv'
def pl2ascii(s)
ascii = "acelnoszzACELNOSZZ"
cep = "\271\346\352\263\361\363\234\277\237\245\306\312\243\321\323\214\257\217"
s = Iconv.new("cp1250", "UTF-8").iconv(s)
s.tr!(cep,ascii)
end
# Pythonic Unicode support
import re
pattern = re.compile(r'(\w+)', re.U|re.I)
msg = unicode('zażółć gęślą jaźń', 'utf-8')
for word in re.findall(pattern, msg):
print '#', word
# zażółć
# gęślą
#!ruby19
# encoding: utf-8
alias :λ :lambda
π = Math::PI
hello_world = λ{|subject| "Hello, #{subject}! π is #{π}"}
puts hello_world["world"] # => Hello, world! π is 3.14159265358979
puts "λπ".length # => 2
Dynamic accessors
<?php
error_reporting(E_ALL);
class String {
static public function capitalize($s) {
if (!empty($s)) return $s = strtoupper($s[0]).strtolower(substr($s,1));
return $s;