Loading

Writing Proxy Server for particular site in PHP with one line (HTTP GET only)

I cannot get access to stackoverflow today again.

So here it is tiny proxy server for http get request, I've written today.

<?php echo preg_replace('|"\/|','"/?x=',file_get_contents('http://stackoverflow.com/'.$_GET["x"]));?>

Cheers,

Memo# Couldn't get access to stackoverflow.com

I couldn't get access to stackoverflow.com almost all the days (only about an hour in the evening, its fine)

- downforeveryorjustme says its down there too
- but just-ping says its almost fine from most place
- it could be my company banned it for local machines
- superuser and serverfault got banned page, but stackovflow and meta aren't, just got
The remote server refuses to perform the request. This address is not available.
- I got it works around 1 hours with Opera Turbo.
- It could be my company banned Opera Turbo too, but some others site like whatismyipaddress.com are fine with Opera Turbo
- Or Stackoverflow banned Opera Turbo? may be because of high traffic on same ip (because its shared by many users?)
- I got 1 hour ok, so its mean banning is not permanent, may be just for few hours for high traffic?

still no clue till now. hopes it will be ok later. or I need to tunnel something with my servers.

Memo# Loop with index in Ruby (alternative to enumerate in Python)

irb(main):033:0* d={"a"=>"x","b"=>"y","c"=>"z"}
=> {"a"=>"x", "b"=>"y", "c"=>"z"}

irb(main):052:0> d.each_with_index{|(k,v),i|puts "key: %s, value: %s, index: %i"% [k,v,i]}
key: a, value: x, index: 0
key: b, value: y, index: 1
key: c, value: z, index: 2
=> {"a"=>"x", "b"=>"y", "c"=>"z"}

PowerShell - Scripting with Windows PowerShell

http://technet.microsoft.com/en-us/scriptcenter/dd742419.aspx

I just gave it a try. most of linux commands are implemented as alias.

and there is regex, array, lots of things there.

to do a text analysis for english its very easy to do like this

it will count words, lines, characters,

cat alice.txt | measure –word –line -character

 Lines                         Words                     Characters
 -----                           -----                       -------------
     4                           137                              707

Nice huh? you should give it a try.

Being a fan of StackOverflow

StackOverflow.com ဆိုတာ အေမးအေျဖ ဆိ္ုဒ္တစ္ခုပာ။ ကမဿဘာတစ္ဝွမ္းက ပညာရွင္ေတြ ဝင္ေရာက္ေျဖဆိုျကတာေတြ့ရမွာပာ။

Programming နဲပတ္သက္ရင္ ေမးခ်င္တာေမးလို့ရပာတယ္။ Server အေျကာင္းေမးခ်င္ရင္ေတာ့ ServerFault.com ဆိုတာ ရွိပာတယ္။ Windows/Linux အေျကာင္းေမးခ်င္ရင္ေတာ့ SuperUser.com ဆိုတာ ရွိပာတယ္။

ေမးထားတာ ေကာင္းမေကာင္း ေျဖထားတာ အသံုးဝင္မဝင္ စတာေတြကို Vote ေပးလို့ရပာတယ္။

စိတ္ဝင္စားဖို့ အရမ္းေကာင္းပာတယ္။ က်ေနာှ အေနနဲ့ေတာ့ Real-Life Game တစ္ခု ကစားရသလိုပာပဲ။

တစ္ခ်ိန္မွာ ျမန္မာဘာသာနဲ့ အဲသလို ဆိုဒ္တစ္ခုေလာက္ လုပ္ခ်င္ပာတယ္။ Forum ထက္ အမ်ားျကီးေကာင္းပာတယ္။

က်ေနာှ အရင္က သိေပမယ့္ မသံုးျဖစ္ခဲ့ပာဘူး။ ေသခ်ာမိတ္ဆက္ေပးတဲ့ ကို အိေမာင္ကို ေက်းဇူးတင္ပာတယ္။

Memo# - Regular Expressions - Part 2 - Substitutions with Grouping

Test String

7800000 (7.8M Characters)

"abbbcdexfbeczexczczkef111anncdehbzzdezf" * 200000

Very Simple Replace

regex pattern: bc , Replace with : TEST , mine is 2.5x faster

my regex sub 0.140000104904 s 8200000 abbTESTdexfbeczexczczkef111anncdehbzzdezfabbTESTdexfbeczexczczkef111anncde....

python's re sub 0.359999895096 s 8200000 abbTESTdexfbeczexczczkef111anncdehbzzdezfabbTESTdexfbeczexczczkef111anncde....

With Range Matching

regex pattern: [a-z]c , Replace with : TEST , mine is 6x faster

my regex sub 0.453000068665 s 9800000 abbTESTdexfbTESTzeTESTTESTzkef111anTESTdehbzzdezfabbTESTdexfbTESTze....

python's re sub 2.82800006866 s 9800000 abbTESTdexfbTESTzeTESTTESTzkef111anTESTdehbzzdezfabbTESTdexfbTESTze....

With Range Matching + Grouping

regex pattern: ([a-z])(c) , Replace with : AA\2\1BB , mine is 27x faster

my regex sub 0.641000032425 s 11800000 abbAAcbBBdexfbAAceBBzeAAcxBBAAczBBzkef111anAAcnBBdehbzzdezfabbAAcbBB....

python's re sub 17.7969999313 s 11800000 abbAAcbBBdexfbAAceBBzeAAcxBBAAczBBzkef111anAAcnBBdehbzzdezfabbAAcbBB....

Cheers,
Mark

#Memo - Syntax Highlighting is Important :D

Syntax Highlighting is Important in Programming :D


Writing Own Regular Expressions Engine for Fun

I have been rewriting my own regex in C just for fun, since I found that python's implementation is not that fast, after reading following article.

<Regular Expression Matching Can Be Simple And Fast (but is slow in Java, Perl, PHP, Python, Ruby, ...)

I only implemented python's findall function. Actually, its relatively fast, but I am just doing it for fun.

Test string Length : 7200000 (7.2M Characters)
Sample : abbbcdexfbeczexczczkefanncdehbzzdezf * 200000
Computer : Mobile Intel Celeron 1.6MHz, 512 MB

1. a bit complicated regex, mine is 2.5x faster than python's re

regex pattern: [a]?[a-b]?[a]?[bezn][a-z0-9_]{1,3}?[e-k][^dsag]f?
my regex: 0.960999965668 s
1000000 matches [u'abbbcdexf', u'beczex', u'zczkef', u'anncdeh', u'bzzdezf', u'abbbcdexf', u'beczex'] .. [u'zczkef', u'anncde
python re: 2.3029999733 s
1000000 matches [u'abbbcdexf', u'beczex', u'zczkef', u'anncdeh', u'bzzdezf', u'abbbcdexf', u'beczex'] .. [u'zczkef', u'anncde

2. simple regex, 5x faster than python's re

regex pattern: [a-z]
my regex: 1.83299994469 s
7200000 matches [u'a', u'b', u'b', u'b', u'c', u'd', u'e'] .. [u'e', u'z', u'f']
python re: 9.35300016403 s
7200000 matches [u'a', u'b', u'b', u'b', u'c', u'd', u'e'] .. [u'e', u'z', u'f']

3. non-greedy matching, 4x faster than python's re

regex pattern: [a-z]{2,5}?
my regex: 1.40199995041 s
3600000 matches [u'ab', u'bb', u'cd', u'ex', u'fb', u'ec', u'ze'] .. [u'zz', u'de', u'zf']
python re: 5.8789999485 s
3600000 matches [u'ab', u'bb', u'cd', u'ex', u'fb', u'ec', u'ze'] .. [u'zz', u'de', u'zf']

4. fix range matching, 4x faster than python's re

regex pattern: [a-z]{5}
my regex: 0.690999984741 s
1440000 matches [u'abbbc', u'dexfb', u'eczex', u'czczk', u'efann', u'cdehb', u'zzdez'] .. [u'fannc', u'dehbz', u'zdezf']
python re: 2.66400003433 s
1440000 matches [u'abbbc', u'dexfb', u'eczex', u'czczk', u'efann', u'cdehb', u'zzdez'] .. [u'fannc', u'dehbz', u'zdezf']

Cheers,
Mark


က်ေနာ္ဖတ္ေသာ အျခား ဘေလာ့ / ဆိုဒ္မ်ား