— Shang Liang

Archive
Tips

Recently my EC2 server was hacked and it was totally my fault. I  enabled  password authentication and I set the password way too simple. I took a look at the log and I found out there are indeed many free people who keep trying to log in using brute force method.

To secure my server, I decided to limit SSH access to my office and home IP addresses only. Here are the steps.

  • Go to “AWS Management Console” and select “Security Groups”
  • Select the security group which is used for the instance, e.g. “quicklaunch-0″
  • Delete the existing SSH access which is set to allow any IP addresses, “0.0.0.0/0″
  • Find out what is your current IP address by searching “what is my ip” in Google (Sorry Bing, you don’t understand this yet. Maybe one day when you grow up).
  • Select SSH from the “Create a new rule” drop down list
  • Customise the “Source” field with your own IP, e.g. “212.157.7.65″ and add “/32″ at the end, which is “212.157.7.65/32″
  • Click “Add rule” and “Apply rule changes”. Now your server only allows this specific IP address to login
  • You can add multiple SSH rules with different IP addresses
  • If you want to allow a range of IP addresses, you need play around with the “/32″ part
  • An IP address has 4 parts, separated by 3 dots. Each part is 8 bit (2 to the power of 8 ) and that makes 255.
  • “/32″ means the IP address allowed to access the server must match all 4 parts (8×4)
  • “/24″ means the IP address allowed to access the server must match the first 3 parts, which means “212.157.7.XXX” is allowed
  • It’s not hard to figure out “/16″ and “/8″ require less matching
  • I’m not sure how to match a specific range e.g. “212.157.7.60 - 212.157.7.200″. Maybe “/29″ will work, but I’m not sure.

I hope this helps.

Read More

In Xcode 3, this is an option to select whether the project uses core data features. If it’s checked, Xcode automatically generates the code to set up the environment. Most of the examples about core data is based on the codes generated by Xcode. However, this feature is taken out in Xcode 4.This post is a guide of how to add the code manually in Xcode 4. Based on that, here’s my version of a simplified routine (it’s only 7 lines without the comments) .

>>Enjoy<<

Read More

Quite often, websites developed in Singapore need to be localized (translated) into other Asian languages. Here’s my experience of working on Asian fonts. This is more useful for Flash designer and developers. But since embedding fonts for HTML is becoming a norm, this may be helpful for HTML work, too.

  1. Most fonts only have English glyphs (characters) and some symbols (punctuations and copyright mark etc.)
  2. Only well established fonts have other latin glyphs (circles and funny heads on top of the letters)
  3. None of the popular fonts (Helvetica or Futura) has Chinese, Thai, Japanese or Korean glyphs
  4. Big Brands’ special fonts (Nokia or Cisco) do not support Asian languages
  5. The only one font has all characters (full unicode set) is Arial Unicode MS
  6. The default local fonts are generally very ugly. Get help from someone who speaks the language to search for a good looking font.
  7. If you embed a font with the full character set the file size will be 12 MB (and most of the Asian countries have slow internet speed)
  8. Thai characters are smaller than other languages’ characters (11px or 10px Thai words are not readable)
  9. Vietnamese characters is a mix of all kinds of latin languages (details here)

Read More

I had a weird error when working with Core Data. The App crashes without giving anything information. After adding break points here and there for  a few hours, I narrowed that the problem is caused by failure to retrieve the NSManagedObjectModel file. I re-created another project and re-created the xcdatamodeld file from scratch and everything works fine. I suddenly remember I edited the xcdatamodeld file with vim when entering the attributes. That must be the reason.

I’m not 100% sure what happened but here’s my guess. The data model file is versioned automatically in Xcode 4. If I edit the “content” file directly, the versioning is disturbed and the IOS won’t be able to locate the “mom” file properly inside the “momd” folder.

Read More
Here’s the step by step instruction:
  1. Create a “installyum.sh” file: vi installyum.sh
  2. Paste the code below inside
  3. Change the [mirror-site-address] to somewhere near you. The list can be found at CentOS’s Website. Remember to change i386 to x86_64 if you are using 64 bit system.
  4. Press Shift+ZZ to save and exit
  5. Grant executable right to the file: chmod +x installyum.sh
  6. Run the script: ./installyum.sh

Here’s the shell script.

for file in \
gmp-4.1.4-10.el5.i386.rpm \
readline-5.1-3.el5.i386.rpm \
python-2.4.3-27.el5.i386.rp \
libxml2-2.6.26-2.1.2.8.i386.rpm \
libxml2-python-2.6.26-2.1.2.8.i386.rpm \
expat-1.95.8-8.3.el5_4.2.i386.rpm \
python-elementtree-1.2.6-5.i386.rpm \
sqlite-3.3.6-5.i386.rpm \
python-sqlite-1.1.7-1.2.1.i386.rpm \
elfutils-libelf-0.137-3.el5.i386.rpm \
elfutils-0.137-3.el5.i386.rpm \
popt-1.10.2.3-18.el5.i386.rpm \
rpm-libs-4.4.2.3-18.el5.i386.rpm \
rpm-4.4.2.3-18.el5.i386.rpm \
rpm-python-4.4.2.3-18.el5.i386.rpm\
m2crypto-0.16-6.el5.6.i386.rpm \
python-urlgrabber-3.1.0-5.el5.noarch.rpm \
python-iniparse-0.2.3-4.el5.noarch.rpm \
yum-fastestmirror-1.1.16-14.el5.centos.1.noarch.rpm \
yum-metadata-parser-1.1.2-3.el5.centos.i386.rpm \
yum-3.2.22-26.el5.centos.noarch.rpm
do rpm -Uvh --nodeps http://[mirror-site-address]/Linux/CentOS/5.5/os/i386/CentOS/$file;
done

Read More

The library is great and it’s very simple to implement. You can follow the instructions on Google to get things ready.

When calling the function, assuming trackPageview, it will be like this

NSError* error;
[[GANTracker sharedTracker] trackPageview:@"/page name" withError:&error]

Just two things to note:

  1. the page name must start with forward slash “/”
  2. withError cannot be nil. If you set the “error” as nil, the system will give you a runtime error.

Read More

I’m spoilt by other IDEs and used to see all my files in my project folder are sorted alphabetically. Xcode does not do that automatically. The newer files are located at the bottom of the folders by default. However, you can drag and drop to arrange them.

I accidentally found out that there is a “Sort” function in the “Edit” menu. Select the folder you want to sort and apply. It will list the files by name or by type based on your choice.

I guess the reason for Xcode not to sort files automatically is due to usability issue. As I am working on my project, some files are seldom opened and some files are edited constantly. It’s quite convenient to drag the more frequently used files onto the top.

Read More

I was following the instructions on this website but I didn’t manage to get the custom fonts working. After trying for a while I found out the problem.

Here’s the updated details of how to use custom fonts in iPhone. This is only available for SDK 4.0 and above.

  1. Add your custom font files into your project using XCode as resources.
  2. Add a key to your info.plist file called “Fonts provided by application” ( Used to be called UIAppFonts).
  3. It’s an array key.
  4. For each font you have, enter the full name of your font file (including the extension).
  5. Save info.plist.
  6. Now in your application you can simply call [UIFont fontWithName:@"CustomFontName" size:12] to get the custom font to use with your UILabels and UITextView.
  7. “CustomFontName” is not the font’s file name. It is the font name registered in the operating system. For example, if you try to use “Bauhaus Medium BT.ttf”, the “CustomFontName” should be “Bauhaus Md BT”, no extension “.ttf” is needed. You need to install the font in your system to find out what name it is. Some fonts have 2 names, you may need FontForge to find out and try which one works.
  8. So far I found out that both ttf and otf format work out of the box. I haven’t tested other font formats yet.

*Points 1-6 credit to http://blog.beefyapps.com/

Read More

I’ve just started using Sass to code CSS. I really like it because it has greatly boosted my ego as a programmer, “I can put programming logic inside my CSS!” And of course, it makes it much easier to manage a complicated CSS. However, I can’t edit scss files with Dreamweaver and I miss seeing the colorful syntax. After searching for a while, I found the solution.

less-scss-syntax-highlighting-in-dreamweaver

It’s quite easy. All you need to do is to find this file Dreamweaver CS?/Configuration/DocumentTypes/MMDocumentTypes.xml and change this line macfileextension=”css” to this macfileextension=”css,scss”.

Read More

I spent hours trying to solve this problem. If you need to load an swf which runs away3d inside it, the loaded swf may get cropped off on the right and bottom sides. Don’t try to set the clipping attributes of the View3D instance. I’ve tried all sorts of clippings but had no luck. The problem lies with the swf’s document dimension. Once that’s set correctly, the cropping problem will be fixed.

Read More