This file contains hidden or 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
| <?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: |
This file contains hidden or 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
| <?php | |
| # What is more readible? | |
| # version 1: | |
| $args[] = '"'.mysql_escape_string(preg_replace("/^'(\d+)$/", '$1', $arg)).'"'; | |
| # version 2: | |
This file contains hidden or 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
| 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. |
This file contains hidden or 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
| <?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(); |
This file contains hidden or 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
| 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| |
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| # 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 |
This file contains hidden or 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
| # 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膮 |
This file contains hidden or 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
| #!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 |
This file contains hidden or 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
| 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; |
OlderNewer