Recent Notes

Displaying keyword search results 1 - 10
Created by magnum on October 22, 2012 20:03:05    Last update: October 22, 2012 20:03:05
First, the test command that sleeps random number of seconds ( sleeper.sh ): #!/bin/bash stime=$[$RANDOM % 20] sleep $sti... As comparison, synchronous pipe code: #include <sys/wait.h> #include <stdio.h> #in... Asynchronous pipe code: #include <sys/wait.h> #include <stdio.h> #in...
Created by Dr. Xi on November 11, 2011 10:05:22    Last update: November 11, 2011 10:12:01
This is an HTML image tag filter using Java regex. It takes a string, finds the img tags, replaces the src attribute with one provided by the filter, then adds a class name to the class attribute. import java.util.regex.*; import java.io.*; ... Test file: <div id="HTML snippet"> <img src="img/big/txt-m...
Created by magnum on September 27, 2011 11:57:49    Last update: October 05, 2011 12:20:00
This procedure sets up an IPSec vpn server on Linux with Preshared Key (PSK) using Openswan . Install Openswan: # yum install openswan Edit /etc/ipsec.conf . This is about the minimum needed to run IPSec server. Instead of running L2TP on port 1701, I'm running TCP on port 8080 so that I can test the setup with nc later. # /etc/ipsec.conf - Openswan IPsec configurati... Edit /etc/ipsec.secrets . # # Preshared key for clients connecting from a... Start IPSec: # /etc/init.d/ipsec start Check status: # ipsec auto --status Monitor IPSec log: # less /var/log/secure If IPSec is running KLIPS, you should see a new nic ( ipsec0 ). There's no ipsec0 if IPSec is running NETKEY. # ifconfig eth0 Link encap:Ethernet HWadd...
Created by magnum on September 27, 2011 13:57:23    Last update: October 03, 2011 13:02:34
After an IPSec connection is established, all traffic between the network interfaces named in /etc/ipsec.conf are tunneled through IPSec. And only the protocols and ports listed in /etc/ipsec.conf are allowed. For example, if you were able to ssh to the server, after IPSec connection ssh is no longer working if port 22 is not listed. Assume that you set up IPSec tunnel between the hosts 192.168.0.1 and 192.168.0.101 , these tests will show that the IPSec connection is successfully working. Before bringing up IPSec connection If IPSec connection is already established, bring it down: # ipsec auto --down TCP8080-PSK-CLIENT Monitor server port 8080 with tcpdump ( 192.168.0.1 ): # tcpdump -i eth0 port 8080 -X On server side ( 192.168.0.1 ), listen on port 8080:...
Created by magnum on September 27, 2011 12:55:51    Last update: September 27, 2011 12:55:51
These steps set up a Linux host as IPSec client, using Openswan . Install Openswan: # yum install openswan Edit /etc/ipsec.conf . Instead of L2TP on port 1701, I'm setting up TCP on port 8080 so that I can test the connection with nc . # /etc/ipsec.conf - Openswan IPsec configuration f... Edit /etc/ipsec.secrets . # include /etc/ipsec.d/*.secrets 192.168.0.101 ... Start IPSec: # /etc/init.d/ipsec start Connect to IPSec server: # ipsec auto --up TCP8080-PSK-CLIENT 104 "TCP80...
Created by freyo on September 09, 2011 11:43:36    Last update: September 09, 2011 11:45:45
When you run automated Android tests with Eclipse or from the command line, you get text output, which isn't good for reporting purposes. If you run a large set of test cases with automated build, the text report isn't very helpful. Fortunately, Android CTS generates test reports in XML with accompanying XSL to make it look nice in a browser. To run your own tests with Android CTS: Download Android CTS Make a new directory MyRepository under android-cts , alongside the existing repository directory. Copy host_config.xml from repository to MyRepository Create directory plans under MyRepository , add a test plan ( MyTests.xml ): <?xml version="1.0" encoding="UTF-8"?> <TestPla... Create directory testcases under MyRepository . Copy TestDeviceSetup.apk from repository/testcases to MyRepository/testcases Under MyRepository/testcases , create a test...
Created by freyo on September 07, 2011 16:46:14    Last update: September 07, 2011 19:23:00
The Android unit test framework is based on JUnit 3 , not JUnit 4. Test cases have to extend junit.framework.TestCase or a subclass (such as android.test.InstrumentationTestCase ). Tests are identified by public methods whose name starts with test , not methods annotated with @Test (as in JUnit 4). An Android test suite is packaged as an APK, just like the application being tested. To create a test package, first you need to identify the application package it is testing. Google suggests to put the test package source in a directory named tests/ alongside the src/ directory of the main application. At runtime, Android instrumentation loads both the test package and the application under test into the same process. Therefore, the tests can invoke methods on...
Created by freyo on August 25, 2011 09:07:40    Last update: August 25, 2011 20:45:43
This is a list of built-in Android permission values: Permission Description Since API Level android.permission.ACCESS_CHECKIN_PROPERTIES Allows read/write access to the "properties" table in the checkin database, to change values that get uploaded. 1 android.permission.ACCESS_COARSE_LOCATION Allows an application to access coarse (e.g., Cell-ID, WiFi) location 1 android.permission.ACCESS_FINE_LOCATION Allows an application to access fine (e.g., GPS) location 1 android.permission.ACCESS_LOCATION_EXTRA_COMMANDS Allows an application to access extra location provider commands 1 android.permission.ACCESS_MOCK_LOCATION Allows an application to create mock location providers for testing 1 android.permission.ACCESS_NETWORK_STATE Allows applications to access information about networks 1 android.permission.ACCESS_SURFACE_FLINGER Allows an application to use SurfaceFlinger's low level features 1 android.permission.ACCESS_WIFI_STATE Allows applications to access information about Wi-Fi networks 1 android.permission.ACCOUNT_MANAGER Allows applications to call into AccountAuthenticators. Only the system can get this permission. 5 android.permission.AUTHENTICATE_ACCOUNTS...
Created by Dr. Xi on July 15, 2011 09:25:15    Last update: July 15, 2011 09:25:15
Some methods to search for a substring within a string: To know that a substring indeed exists within a string: boolean found = wholeString.contains(substring); To find where the substring is contained: int index = wholeString.indexOf(substring); If the substring is regex: boolean match = wholeString.matches(".*" + substri... Case insensitive match: convert both whole string and substring to lowercase, then compare. Or, use case insensitive flag for regex. Test code: import java.util.regex.*; public class Stri...
Created by freyo on April 01, 2011 14:29:25    Last update: June 29, 2011 13:58:27
Start the emulator ( create an AVD if none exists) $ tools/emulator -avd Simple8 Create new project $ tools/android create project \ > --package co... where " --target 2 " identifies the target platform as displayed by " tools/android list targets ", which is stored in the properties file default.properties in the project root folder. cd HelloWorld and install debug package onto the running emulator: $ ant install Buildfile: build.xml [set... Launch the Hello World application on the emulator. You'll see something like this: Edit res/values/string.xml , change the contents to: <?xml version="1.0" encoding="utf-8"?> <resourc... Edit res/layout/main.xml , change the contents to: <?xml version="1.0" encoding="utf-8"?> <LinearL... The contents of the text area now refer to a string defined in the resource file strings.xml , instead...
Previous  1 2 3 Next