2012年1月15日 星期日

Install Samba on FreeBSD 8.2


root@bmw0 [/root] # cd /usr/ports/net/samba36; make install clean

Edit smb.conf

root@bmw0 [/root] # vi /usr/local/etc/smb.conf
security = user
hosts allow = 192.168.100. 192.168.200.168 127.

[syncdb]
comment = hmm
path = /usr/local/www/apache22/data/syncdb
valid users = sambauser
public = no
writable = yes
printable = no
create mask = 0640
; write list = @staff

Add a user called "sambauser"
root@bmw0 [/root] # adduser

Adding users to samba
root@bmw0 [/root] # smbpasswd –a
or
root@bmw0 [/root] # /usr/local/bin/pdbedit -a username

Start Samba
root@bmw0 [/root] # /usr/local/etc/rc.d/samba start

Check to see if samba is running
root@bmw0 [/root] # ps -auwxx | egrep '[sn]mbd'

Test samba using smbclient
root@bmw0 [/root] # /usr/local/bin/smbclient -U username \\\\localhost\\username
or
root@bmw0 [/root] # /usr/local/bin/smbclient -U username //localhost/username

Edit rc.conf
root@bmw0 [/root] # vi /etc/rc.conf
### Samba
samba_enable="YES"
nmbd_enable="YES"
smbd_enable="YES"

Edit ipfw.rules
root@bmw0 [/root] # vi /usr/local/etc/ipfw.rules
### samba
$IPF 260 allow tcp from 192.168.100.0/24 to any 139 in

Refernce To:http://gala4th.blogspot.com/2012/01/install-samba-on-freebsd-82.html

2012年1月10日 星期二

Install Nginx, PHP-FPM and Varnish on FreeBSD 8.2

Install Nginx, PHP-FPM and Varnish on FreeBSD 8.2

# cd /usr/ports/www/nginx

# make install clean

Note: make sure you select important option such as:
HTTP_REWRITE_MODULE=on
HTTP_SSL_MODULE=on

and others as per your requirements.

# echo '### Nginx' << /etc/rc.conf
# echo 'nginx_enable="YES"' << /etc/rc.conf

# vim /usr/local/etc/nginx/nginx.conf
gzip on;
    gzip_min_length 1000;
    gzip_proxied expired no-cache no-store private auth;
    gzip_disable "MSIE [1-6]\.";
    gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;

    server {
            server_name mydomain1.com mydomain2.com mydomain3.com;
            root /usr/local/www/nginx/drupal7; ## <-- Your only path reference.

            client_max_body_size 20M; # Maximum allowed size for uploaded files

            location = /favicon.ico {
                    log_not_found off;
                    access_log off;
            }

            location = /robots.txt {
                    allow all;
                    log_not_found off;
                    access_log off;
            }

            # This matters if you use drush
            location = /backup {
                    deny all;
            }

            # Very rarely should these ever be accessed outside of your lan
            location ~* \.(txt|log)$ {
                    allow 192.168.0.0/16;
                    deny all;
            }

            location ~ \..*/.*\.php$ {
                    return 403;
            }

            location / {
                    # This is cool because no php is touched for static content
                    try_files $uri @rewrite;
            }

            location @rewrite {
                    # Some modules enforce no slash (/) at the end of the URL
                    # Else this rewrite block wouldn't be needed (GlobalRedirect)
                    rewrite ^/(.*)$ /index.php?q=$1;
            }

            location ~ \.php$ {
                    fastcgi_split_path_info ^(.+\.php)(/.+)$;
                    ### NOTE: You should have "cgi.fix_pathinfo = 0" in php.ini
                    include fastcgi_params;
                    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                    fastcgi_intercept_errors on;
      #fastcgi_pass 127.0.0.1:9000;  #pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
                    fastcgi_pass unix:/tmp/php-fpm.sock;
            }

            # Fighting with ImageCache? This little gem is amazing.
            location ~ ^/sites/.*/files/imagecache/ {
                    try_files $uri @rewrite;
            }
            # Catch image styles for D7 too.
            location ~ ^/sites/.*/files/styles/ {
                    try_files $uri @rewrite;
            }

            location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
                    expires max;
                    log_not_found off;
            }

            # nginx status
            location /NginxStatus {
              stub_status on;
              access_log on;
              auth_basic NginxStatus;
              auth_basic_user_file conf/htpasswd;
            }
    }

# /usr/local/etc/rc.d/nginx start

Change this line for nginx:

# vim /usr/local/etc/php.ini
cgi.fix_pathinfo = 0

Install php and php-fpm:

// For PHP5.3
# cd /usr/ports/lang/php5 ; make install

// For PHP5.2
# cd /usr/ports/lang/php52 ; make install

===< The following configuration options are available for php5-5.3.8:
CLI=on "Build CLI version"
CGI=on "Build CGI version"
FPM=on "Build FPM version (experimental)"
APACHE=off "Build Apache module"
AP2FILTER=off " Use Apache 2.x filter interface (experimental)"
DEBUG=off "Enable debug"
SUHOSIN=on "Enable Suhosin protection system"
MULTIBYTE=on "Enable zend multibyte support"
IPV6=off "Enable ipv6 support"
MAILHEAD=on "Enable mail header patch"
LINKTHR=on "Link thread lib (for threaded extensions)"
===< Use 'make config' to modify these settings

// For PHP5.3
# cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini

// For PHP5.2
# cp /usr/local/etc/php.ini-recommended /usr/local/etc/php.ini

Install PHP Extensions
// For PHP5.3
# cd /usr/ports/lang/php5-extensions ; make install

// For PHP5.2
# cd /usr/ports/lang/php52-extensions ; make install

Edit php-fpm.conf:
# vim /usr/local/etc/php-fpm.conf
; comment out following line and add the line below.
;listen = 127.0.0.1:9000
listen = /tmp/php-fpm.sock

request_terminate_timeout=30s

Edit rc.conf
# vim /etc/rc.conf
### php-fpm
php_fpm_enable="YES"

Change this line for nginx

# vim /usr/local/etc/php.ini
cgi.fix_pathinfo = 0

# /usr/local/etc/rc.d/php-fpm start

# tail /var/log/nginx-error.log

# tail /var/log/php-fpm.log

# tail /var/log/messages

Install Varnish

# cd /usr/ports/www/varnish ; make install clean

Reconfigure your web server to listen on localhost:8080

# echo 'varnishd_enable="YES"' << /etc/rc.conf
# echo 'varnishd_flags="-s malloc,1G -a 127.0.0.1:80 -b 127.0.0.1:8080"' << /etc/rc.conf
# echo 'varnishlog_enable="YES"' << /etc/rc.conf

# /usr/local/etc/rc.d/varnishd start

# /usr/local/etc/rc.d/varnishncsa onestart

# tail /var/log/varnishncsa.log

# /usr/local/bin/varnishtest

# /usr/local/bin/varnishstat

# ls -lh /usr/local/varnish/`hostname`

Install webbench
# cd /usr/ports/benchmarks/webbench ; make install clean

# webbench -c 3000 -t 60 http://test.local/index.php


Refernce To: http://gala4th.blogspot.com/2012/01/install-nginx-php-fpm-and-varnish-on.html

2011年12月21日 星期三

Finding the Unique Device ID in Windows Phone 7 (And Device Manufacturer And Anonymous Windows Live ID)


  • Device Manufacturer ID
    • DeviceExtendedProperties.TryGetValue(“DeviceManufacturer”, out someObject);
    • example: “HTC”
  • Device ID
    • DeviceExtendedProperties.TryGetValue(“DeviceUniqueId”, out someObject);
    • requires ID_CAP_IDENTITY_DEVICE in the app manifest which will trigger a warning to users when they install the app
    • a byte[], converter to a string will looks like
      “12345678901234567890123456789012345678901234567890123”
  • Anonymous Windows Live ID
    • A 32 character subset at offset 2  of the results of
      “UserExtendedProperties.TryGetValue(“ANID”, out someObject)
    • requires ID_CAP_IDENTITY_USER in the app manifest which will trigger a warning to users when they install the app
    • looks like “00FF00FF00FF00FF00FF00FF00FF00FF”
However, if you just need any unique identifier (not necessarily a device ID), you can always set and store a new global unique identifier using:
Guid.NewGuid();
which will return a 128-bit integer that will look something like this:
“e81644f1-46b6-4994-2903-1d1f1440c130″
This will not cause warnings to appear when the app is downloaded because it isn’t a constant identifier to that specific device.
Reference To:

SQLite on WP7


“C# Sqlite Port for Windows phone 7 and possibly Silverlight 3, 4. The core engine was slightly modified to be used with IsolatedStorage and SqliteClient were ported by using missing codes from Mono project in order to maximize usability and portability from desktop.”
Although sterling works great, it is essentially an object-based database (NoSql-like)… If you truly need a relational database or if your application currently uses SQLite and you want to port it to Windows Phone 7, this might just be the answer!
Let’s get started… As with traditional ADO.NET, we first need to create a connection:
using (SqliteConnection conn = 
 new SqliteConnection("Version=3,uri=file:Super14Database.db"))
{
    conn.Open();
    // Use the connection here...
}
And now we can start using the database with “normal” SQL statements… Let’s create a table.
using (SqliteCommand cmd = conn.CreateCommand())
{
    cmd.CommandText = "CREATE TABLE matches ( [id] INTEGER PRIMARY KEY, _
 [team1] TEXT, [score1] INTEGER, [team2] TEXT, [score2] TEXT, [date] TEXT)";
    cmd.ExecuteNonQuery();
}
And to insert data:
cmd.Transaction = conn.BeginTransaction();
cmd.CommandText = "INSERT INTO matches(score1, team1, 
 score2, team2, date) VALUES(@score1, @team1, @score2, @team2, @date);";

cmd.Parameters.Add("@score1",  null);
cmd.Parameters.Add("@team1", null);
cmd.Parameters.Add("@score2",  null);
cmd.Parameters.Add("@team2",  null);
cmd.Parameters.Add("@date",  null);

cmd.Parameters["@score1"].Value = 20;
cmd.Parameters["@team1"].Value =  "Blues";
cmd.Parameters["@score2"].Value =  34;
cmd.Parameters["@team2"].Value =  "Hurricanes";
cmd.Parameters["@date"].Value =  "12/02/10";
cmd.ExecuteNonQuery();


cmd.Parameters["@score1"].Value =  15;
cmd.Parameters["@team1"].Value =  "W Force";
cmd.Parameters["@score2"].Value =  24;
cmd.Parameters["@team2"].Value =  "Brumbies";
cmd.Parameters["@date"].Value =  "12/02/10";
cmd.ExecuteNonQuery();

cmd.Parameters["@score1"].Value =  34;
cmd.Parameters["@team1"].Value =  "Cheetahs";
cmd.Parameters["@score2"].Value =  51;
cmd.Parameters["@team2"].Value =  "Bulls";
cmd.Parameters["@date"].Value =  "12/02/10";
cmd.ExecuteNonQuery();

cmd.Parameters["@score1"].Value =  32;
cmd.Parameters["@team1"].Value =  "Crusaders";
cmd.Parameters["@score2"].Value =  17;
cmd.Parameters["@team2"].Value =  "highlanders";
cmd.Parameters["@date"].Value =  "12/02/10";
cmd.ExecuteNonQuery();

cmd.Parameters["@score1"].Value =  28;
cmd.Parameters["@team1"].Value =  "Reds";
cmd.Parameters["@score2"].Value =  30;
cmd.Parameters["@team2"].Value =  "Waratahs";
cmd.Parameters["@date"].Value =  "12/02/10";
cmd.ExecuteNonQuery();

cmd.Parameters["@score1"].Value =  13;
cmd.Parameters["@team1"].Value =  "Lions";
cmd.Parameters["@score1"].Value =  26;
cmd.Parameters["@team2"].Value =  "Stomers";
cmd.Parameters["@date"].Value =  "12/02/10";
cmd.ExecuteNonQuery();

cmd.Parameters["@score1"].Value =  18;
cmd.Parameters["@team1"].Value =  "Sharks";
cmd.Parameters["@score2"].Value =  19;
cmd.Parameters["@team2"].Value =  "Chiefs";
cmd.Parameters["@date"].Value =  "12/02/10";
cmd.ExecuteNonQuery();
                    
cmd.Transaction.Commit();
NOTE: Notice the transaction support build in!
To fetch data from the database:
cmd.CommandText = "SELECT * FROM matches";
using (SqliteDataReader reader = cmd.ExecuteReader())
{
    while (reader.Read())
    {
        var team1 = reader.GetValue(1);
        var score1 = reader.GetValue(2);
        var team2 = reader.GetValue(3);
        var score2 = reader.GetValue(4);
        var date = reader.GetValue(5);
    }
}
And that’s it! It is more verbose but it does work great and the translation from a normal desktop application that used SQLite should be simple!


Reference To:
http://www.codeproject.com/Articles/151179/SQLite-on-WP7

Windows Phone 7 Emulator Skin Switcher 1.0 Beta


In the last few weeks several people started creating their own skins for the Windows Phone 7 Emulator. Switching between different skins was a lot of work by copying files manually to the emulator directory every time you wanted to switch. From now on this is not needed anymore because you can use the Windows Phone 7 Emulator Skin Switcher application I’ve created.
wp7EmulatorSkinSwitcher
You can download the application here: Download
This version is the first beta release with my first set of skins. I added 2 skins from Georg Kalus: the Blue Nokia Lumia 800 and the White/Pink Nokia Lumia 710. I’ve also included the Black Nokia Lumia 800 skin from Pedro Lamas
The complete list of skins included in the application now are:
I’m planning on adding more skins in the near future but didn’t have time for it yet. If you have skins I can use please let me know by comment or on twitter
lumia710whitelumia800pinklumia710black

Hopefully this will make your Windows Phone 7 projects even more fun to test!

2011年12月19日 星期一

How To Change Your Windows Phone Emulator?


Today, I discovered that Pedro Lamas had released a skin for the Windows Phone emulator that allowed it to look like the Nokia Lumia 800.  (You can see it here.)
This inspired me to create another new skin for my current phone, the HTC Arrive.  (Click here to download the HTC Arrive Windows Phone Emulator skin.)  To use either of them, you simply need to copy the contents of the zip file to a specific folder on your computer (make sure to save a copy of the original files):

C:\Program Files (x86)\Microsoft XDE\1.0\

Once you’ve done that, your emulator can look like one of the images below!
Nokia-Lumia-800-skin-for-Windows-Phone-Emulator[1]                                  image
Reference To:http://www.jeffblankenburg.com/2011/12/17/want-to-change-your-windows-phone-emulator/

2011年11月29日 星期二

HowTo - 在 Windows 7 、Vista 忘記 Administrator 密碼


To reset a forgotten administrator password, follow these steps:

  1. Boot from Windows PE or Windows RE and access the command prompt.
  2. Find the drive letter of the partition where Windows is installed. In Vista and Windows XP, it is usually C:, in Windows 7, it is D: in most cases because the first partition contains Startup Repair. To find the drive letter, type C: (or D:, respectively) and search for the Windows folder. Note that Windows PE (RE) usually resides on X:.
  3. Type the following command (replace “c:” with the correct drive letter if Windows is not located on C:):
    copy c:\windows\system32\sethc.exe c:\
    This creates a copy of sethc.exe to restore later.
  4. Type this command to replace sethc.exe with cmd.exe:
    copy /y c:\windows\system32\cmd.exe c:\windows\system32\sethc.exeReboot your computer and start the Windows installation where you forgot the administrator password.
  5. After you see the logon screen, press the SHIFT key five times.
  6. You should see a command prompt where you can enter the following command to reset the Windows password (see screenshot above):
    net user your_user_name new_password
    If you don’t know your user name, just type net user to list the available user names.
  7. You can now log on with the new password.
I recommend that you replace sethc.exe with the copy you stored in the root folder of your system drive in step 3. For this, you have to boot up again with Windows PE or RE because you can’t replace system files while the Windows installation is online. Then you have to enter this command:
copy /y c:\sethc.exe c:\windows\system32\sethc.exe