Skip to content

Instantly share code, notes, and snippets.

View paulononaka's full-sized avatar

Paulo Henrique Nonaka paulononaka

  • Belo Horizonte, MG - Brazil
View GitHub Profile
@paulononaka
paulononaka / AndroidGetPropSystem.java
Created March 18, 2011 14:51
Getting a system property in Android
public static String getPropSystem(String key) throws IOException {
BufferedReader bis = null;
try {
Process ifc = Runtime.getRuntime().exec("getprop " + key);
bis = new BufferedReader(new InputStreamReader(ifc.getInputStream()));
return bis.readLine();
} finally {
bis.close();
}
}
@paulononaka
paulononaka / AndroidSettingDateTime.java
Created March 18, 2011 15:20
Setting a specific date/time in Android.
private void settingDeviceDateTime(Date date) {
Calendar c = Calendar.getInstance();
c.setTime(date);
SystemClock.setCurrentTimeMillis(c.getTimeInMillis());
Log.d(TAG, "Setting time to: " + new SimpleDateFormat("MM/dd/yyyy hh:mm:ss").format(c.getTime()));
}
@paulononaka
paulononaka / AndroidGetSystemProp.java
Created March 23, 2011 19:33
A better way to get a system property.
public static String getSystemProp(String key) throws Exception {
Class<?> c = Class.forName("android.os.SystemProperties");
Class<?>[] types = new Class[] {String.class};
Method method = c.getMethod("get", types);
return (String) method.invoke(null, new Object[] {key});
}
@paulononaka
paulononaka / AndroidInstallApk
Created April 5, 2011 20:54
Install an apk calling the installation screen default Android
public static void installApk(Context context, File apkFile) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive");
context.startActivity(intent);
}
@paulononaka
paulononaka / JavaIntToLittleEndianUnsigned
Created April 7, 2011 17:22
Convert a Int (in Java, big endian signed) to LittleEndian unsigned
private static byte[] intToLittleEndian(long numero) {
ByteBuffer bb = ByteBuffer.allocate(4);
bb.order(ByteOrder.LITTLE_ENDIAN);
bb.putInt((int) numero);
return bb.array();
}
// OR ...
private static byte[] intToLittleEndian(long numero) {
@paulononaka
paulononaka / AndroidGetIPaddress.java
Created June 20, 2011 14:18
Get IP address of device in android. The method returns the device ip address which is currently used by device irrespective of type of connection ie.,either 3g/wifi/any other.
public static String getIPAddress() throws SocketException {
for (Enumeration<?> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
NetworkInterface intf = (NetworkInterface) en.nextElement();
for (Enumeration<?> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
InetAddress inetAddress = (InetAddress) enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress()) {
return inetAddress.getHostAddress().toString();
}
}
}
@paulononaka
paulononaka / Git tips
Last active December 15, 2015 15:59
git tips
== last commit that changed a specific file
git rev-list -n 1 HEAD -- <file_path>
== checkout file from commit
git checkout <deleting_commit>^ -- <file_path>
== list files changed in one specific commit

Capybara

save_and_open_page

Matchers

have_button(locator)
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
$(document).ready(function() {
$form = $("#signup-form");
$form.bind("ajax:beforeSend", function(evt, xhr, settings){
var $submitButton = $form.find('.btn-submit');
$submitButton.attr("disabled", true);
$submitButton.data('origText', $submitButton.text());
$submitButton.text("Cadastrando..." );
})