RSA Decryption on iOS

I’ve been googled for few days and struggling on “How to decrypt cipher text in iOS”, unfortunately there is no solution were found.

Read More

Show chinese subtitle on VLC player in OS X

I’ve facing an issue on display the chinese character in not readable form.

I googled and found this blog to show in windows platform.

Read More

ZendFramework 2 - Construct SQL with subquery

A scenario here:

A Q & A website that allow user to ask question and put several tags to that question.

Read More

ZendFramework 2 - Construct AND OR SQL

I believe that almost all the web applications have a function Search, thus you might need to construct a query like:

1
2
3
4
SELECT *
FROM foo INNER JOIN bar ON foo.id = bar.foo_id
WHERE (foo.attr_1 LIKE '%abc%' OR foo.attr_2 LIKE '%abc%')
AND (bar.attr_1 LIKE '%xyz%' OR bar.attr_2 LIKE '%xyz%')

Read More

ZendFramework 2 - Create a custom view helper

For many situations, we need some helper functions to be used in view.

i.e. When you want to debug, probably you will write

./module/Application/view/application/index/foo.phtml

Read More

Ubuntu server allow login via ssh with key

The environment:

  • Ubuntu server 12.04 LTS is running on VMWare Fusion with IP address 192.168.1.101 as Host
  • Mac OS X Mountain Lion as Client

Read More

Crawling images from a webpage

First extract the url of images
craw.py

1
2
3
4
5
6
7
8
9
10
import urllib2, re
req = urllib2.Request('http://yourwebsite.com/path/to/webpage')
website = urllib2.urlopen(req)

html = website.read()

# Read all png files
imgs = re.findall('"((http)s?://.*?.png)"', text)
for i in imgs:
print i[0]

Read More

Django - Redirect URL to facebook oAuth

In your views.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from django.http import HttpResponse
from projectname import settings
from urllib import urlencode

def index(request):
params = {
'client_id': settings.FACEBOOK_APP_ID,
'redirect_uri': 'https://www.facebook.com/yourappname/app_' + settings.FACEBOOK_APP_ID,
'scope': 'email,user_birthday,offline_access,publish_stream',
}
redirect_url = 'https://www.facebook.com/dialog/oauth/?' + urlencode(params)
redirect_code = """
<script type="text/javascript">
top.location.href = '%s';
</script>
""" % redirect_url;

return HttpResponse(redirect_code, mimetype='text/html')

Read More

Python: Make a GET request to get JSON data

Make a HTTP request to get JSON content from website.

Create a file json_helper.py

1
2
3
4
5
6
7
8
9
import urllib2
import json

def get_json_by_user_id(user_id):
header = {'Content-Type': 'application/json',}
req = urllib2.Request('http://www.example.com/getmyjson?user_id=' + user_id)
website = urllib2.urlopen(req)

return json.loads(website.read())

Read More

Create Facebook page app using Django with Nginx

This is continue from previous post.

Enable SSL

As we know that Facebook app required SSL, so first we must self-sign a certificate

Read More