Monday, August 25, 2014

Why libimobiledevice are good. or List all iDevices connected to a host.

a note to meself

for i in `idevice_id --list`;
do 
  ideviceinfo -u $i |grep "^SerialNumber\|^DeviceName"; 
done;

Monday, August 11, 2014

A very good introduction to Objective-C

There are tons of documentation on Objective-C on the internet, but most of it is written in the style of "we do it this way, because Apple says so".

Happily, there is a good intro to Objective-C by Pierre Chatelier. The intro is written in style "Objective-C for C++ developers" and it is in good details, explanations and examples.


Here is what Pierre says on the subject:

"The Objective-C language (C++ "challenger"), is not very widely spread outside MacOSX / Cocoa world. However, it is really worth studying. Unfortunately, the few documentations that can be found are targeted most of the time to OOP beginners. Therefore, an advanced C++ developer cannot find quickly the equivalents of its usual techniques : time is lost at exploring the language.
So, I have tried to gather in this document a lot of C++ and Objective-C concepts, to show how to switch from one to another and understand the Objective-C paradigms. I hope that it will help good developers to rapidly adopt Objective-C."


And here is the book itself

Have fun reading.


Wednesday, August 6, 2014

Groovy and XML parsing

Yo!

Say we count books in genres in a book shop that has it's data in big xml file:

Let's use Groovy

def xml = new XmlSlurper().parse("/home/user/bigXML.xml")
xml.genres.genre.each {
    println "Genre " + it.'@genre_name' + " has this many books: " + it.books.book.size()
}


src
http://groovy.codehaus.org/Reading+XML+using+Groovy%27s+XmlParser

IDEA appeared to be a nice IDE for Groovy

Tuesday, August 5, 2014

A very nice file system for storing photos and videos

NULLFS https://github.com/xrgtn/nullfs


nop. Just kidding. Do not use for storing any-valuable data.
Just a very useful and fast FS for testing you applications.

7 red lines


Yo! Can you draw 7 perpendicular red lines with different color?

 http://youtu.be/BKorP55Aqvg


Origin http://alex-aka-jj.livejournal.com/66984.html

Purging disk cache to see mor free RAM on Mac OS X

It is frightening when there is little amount of free RAM displayed by top command.

Most of time on an idle mac it can be fixed by purge command (to force disk cache to be purged).

sudo purge # do not use. see important note below

On GNU/Linux there is another way round (as usual).

sudo -s
echo 3 > /proc/sys/vm/drop_caches



Important update!!
Do not use sudo purge  on Mac OS X!
it turned out it is dangerous. Just reboot the Mac.

auto install and upgrade Android SDK

Yo!

Say there is a need to install Android SDK automatically on a farm of headles Linux servers in clouds (Amazon AWS, whatever). Here is a nice script:

#!/bin/bash
set -x
cd ~

if [ -d android-sdk ]
then
  rm -rf android-sdk
fi

if [ ! -f android-sdk_r22.6.2-linux.tgz ]
then
fi

if [ ! -d android-sdk-linux ]
then
 tar -zxvf android-sdk_r22.6.2-linux.tgz
fi

ANDROID_HOME=~/android-sdk-linux/
PATH=${ANDROID_HOME}/tools:${ANDROID_HOME}/platform-tools:${PATH}
export ANDROID_HOME PATH

components_to_install=`$ANDROID_HOME/tools/android list sdk -a |grep -E '(SDK Tools|Platform.*API 1[0-9]|Platform-tools|Build-tools|Intel x86|Web Driver|Support Library)'`
echo -e "Will install following components \n $components_to_install"
list_of_components_to_install=`echo "$components_to_install"| sed -e 's/^ \+//g' | grep -E '^[0-9]'|sed -rn 's/^([[:digit:]]+).*/\1/p' | perl -p -e 's/\n/,/' |sed -e 's/,$//g'`
echo "components to install in CSV $list_of_components_to_install"
android_cmd="$ANDROID_HOME/tools/android update sdk -u -a --filter $list_of_components_to_install"
(while :
do
  echo 'y'
  sleep 4
done) | bash -c "$android_cmd"


Qemu and it's overlay images magick

Qemu is good! Very good!

It can use snapshots. It can use snapshots of snapshots. It can save delta to snapshot.

http://kashyapc.fedorapeople.org/virt/lc-2012/snapshots-handout.html

just to be here.


Parallel SVN up for workspace with svn:externals

Yo, svn users!
Say we have a workspace with lots of svn projects. And workspace is related to the project via svn:externals property.


Here is a nice short script that saves a lot of time performing svn update in parallel:


#!/bin/bash
set -x
if [ -z "$1" ]
then
SVN_REV=""
else
SVN_REV="-r $1 "
fi

svn up --ignore-externals ${SVN_REV} .

svn pg svn:externals . | \
  grep -v "^$" | \
  sed -e "s/\^//g" | \
  awk '{ print "svn co https://my_repo.com"$1" "$2 }' | \
  sed -e 's/$/ \&/g' \
  > _svn_up_parallel

cat _svn_up_parallel
bash _svn_up_parallel
rm _svn_up_parallel


script description:

  grep -v "^$"  - removes empty strings from svn:externals
  sed -e "s/\^//g"  - removes ^ from lines
  awk '{ print "svn co https://my_repo.com"$1" "$2 }'  - converts record from 
           "/my_project1/trunk my_project1" to "https://my_repo.com/my_project1/trunk my_project1"

  sed -e 's/$/ \&/g' - inserts a " &" at the end of each line to send the command to background

RubyDocs

Do not read ruby docs other than http://ruby-doc.com/docs/ProgrammingRuby/

Installing Appium on Linux as 1,2,3


1. install node.js
2. install grunt
3. install appium
tar -zxvf node-v0.10.29-linux-x64.tar.gz
cd node-v0.10.29-linux-x64/bin
./npm install -g grunt-cli
./npm install -g appium


XPath and case insensitive string comparison

Yo, test engineers!

Say we have a web page with a list of genres in a book shop. And we want to make sure that "Sci-Fi" genre is in the list.
Create a test that finds an element with "Sci-Fi" text on it.

 XPath for the test could look like:  "//*[@id='BookGenres'][ . = 'Sci-Fi']"

Bingo. Test works t works!

Let's say we have another shop with it's own web pages, but genres are in capital letters - i.e. "SCI-FI".

The test here stops working which makes test engineer upset.

To make test engineer we could compare strings case-insensitive. With XPath 1.0 it could be difficult.

Let's use "translate" function which takes following arguments:
(
string_to_transform, 
what_element_of_string_to_transform, 
how_to_transform_elements
)

Here is a new XPath and test will work on both "Sci-Fi" and "SCI-FI"

"//*[@id='BooksGenre'][translate(., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = 'Sci-Fi']"

Happy testing!

Tuesday, May 27, 2014

Mockito mock implements a new interface

java.lang.ClassCastException: org.openqa.selenium.WebElement$$EnhancerByMockitoWithCGLIB$$400e318a cannot be cast to org.openqa.selenium.internal.Locatable  java:1145)    
Foo mock = Mockito.mock(Foo.class, withSettings().extraInterfaces(Bar.class));
http://stackoverflow.com/a/1270723

Monday, May 19, 2014

Overriding Gradle's JavaExec task from project's depends.gradle file

  for example you have JavaExec task configured elsewhere as Gradle's plugin 
 and in current project you want to add/override jvmArgs for that task   

 solution:    
myTask {    
    jvmArgs "-Xmx256m"  
}    

Passing JVM args to Gradle (configuring Gradle)

use GRADLE_OPTS

for example 

GRADLE_OPTS=-Xmx512m
export GRADLE_OPTS
gradlew myTask



  

Wednesday, April 30, 2014

Saturday, March 22, 2014

weinre



INSTALL

- unzip.
- go to node/bin
./npm install -g weinre


RUN
- go to node/bin and execute *./weinre --boundHost -all-*


REMOTE DEBUG CLIENT

embed in every page for test <script src="http://10.165.41.84:8080/target/target-script-min.js#anonymous"></script>

Wednesday, March 12, 2014

Limiting outgoing traffic on linux host (Simulating slow connection) as 1,2,3

iptables -t mangle -F
tc qdisc del dev enp0s25 root                                                      ### Delete all TC rules for enp0s25 
tc qdisc add dev enp0s25 root handle 1:0 htb                                       ### Activate queueing discipline
tc class add dev enp0s25 parent 1:0 classid 1:10 htb rate 100kbps ceil 100kbps prio 0  ### Define class allowed 2500kbit burst to 2500kbit (kbps=kiloBYTES)
iptables -A OUTPUT -t mangle -p tcp --dport 8091 -j MARK --set-mark 10             ### Create iptables mangle rule for outgoing port 8091
iptables -A OUTPUT -t mangle -p tcp --sport 8091 -j MARK --set-mark 10             ### Create iptables mangle rule for outgoing port 8091
tc filter add dev enp0s25 parent 1:0 prio 0 protocol ip handle 10 fw flowid 1:10   ### Assign the rule to the proper qdisc
tc -s -d class show dev enp0s25
iptables -t mangle -n -v -L
watch -n 1 tc -s -d class show dev enp0s25