Archives 2005 - 2019    Search

Javascript state machines

published Jul 08, 2013 04:25   by admin ( last modified Jul 08, 2013 04:26 )

ifandelse/machina.js · GitHub

jakesgordon/javascript-state-machine · GitHub

When you lose control of the javascript code and the code controls you, it's time to refactor. But into what? It is tempting to go with one of the MVC frameworks, with different definitions of the letters. But as I was looking at my code and thought "What is the simplest way of representing this?", it seemed to point in the direction of a state machine. Will report back with news.


Make text bigger on phonegap

published Jul 03, 2013 03:35   by admin ( last modified Jul 04, 2013 03:34 )

On phonegap, pages had much smaller text than when being viewed in the system web browser on Android. The following change in the viewport rectified that:

 

target-densitydpi=medium-dpi


Read more: Link - javascript - Phonegap Application text and layout too small - Stack Overflow


Superstop - get rid of animations in gifs in Firefox

published Jul 03, 2013 03:19   by admin ( last modified Jul 03, 2013 03:19 )



SuperStop is very simple: it adds a Shift+Esc shortcut that stops active WebSocket connections, XMLHttpRequests, and any animated images, regardless of the state of the Firefox Stop button. This matches the behavior of the Esc button in versions of Firefox prior to Firefox 20 (see bug 824248).


Read more: Link - SuperStop :: Add-ons for Firefox


Speed up Android devices on Linux by an order of magnitude

published Jul 02, 2013 10:35   by admin ( last modified Sep 25, 2013 11:59 )

When installing the Android development tools from Google, I read that hardware acceleration for the Android Virtual Devices (the Virtual phones on screen that you can test your software on) would not be avilable for Linux.

 

However Intel says it is available. I have tested it and I now fully believe their claims that you can speed up your testing device by a factor of five or ten! Follow the link below to check how to do it.

 

It's basically:

sudo apt-get install qemu-kvm libvirt-bin ubuntu-vm-builder bridge-util

 

If you are an Android* developer who is unhappy with the performance of the Android emulator, then this document is for you. Over and over again, we have heard from many Android developers that the emulator is slow and painful to work with, but this should not be the case!


Read more: Link - Speeding Up the Android* Emulator on Intel® Architecture | Intel® Developer Zone


lz-string, javascript to cram more data into localstorage

published Jul 01, 2013 11:55   by admin ( last modified Jul 01, 2013 11:55 )

Without it, I got 2300 items of my data into Chrome, with it  I got 6300, well probably more but I did not need more.

 

lz-string was designed to fulfill the need of storing large amounts of data in localStorage, specifically on mobile devices. localStorage being usually limited to 5MB, all you can compress is that much more data you can store.


Read more: Link - lz-string: JavaScript compression, fast! - pieroxy.net


Domain White List on Android 2.3 on newer phonegaps (e.g. 2.8)

published Jun 29, 2013 10:40   by admin ( last modified Jun 29, 2013 10:43 )

Summary:

Add this class: https://github.com/android/platform_frameworks_base/blob/master/core/java/android/webkit/WebResourceResponse.java

delete the line that says:

import android.net.http.Headers;
...it is not used anywhere.

 

Newer versions of Codova/Phonegap does not support domain white listing when running the resulting app on Android 2.3 devices. The error message is:

Could not find class 'android.webkit.WebResourceResponse', referenced from method org.apache.cordova.CordovaWebViewClient.getWhitelistResponse

Reason is that is looking for the WebResourceResponse class and cannot find it. Just download it from github at the afore mentioned address, and put in your source tree.

The incompatibility with Android 2.3 seems to have crep t in in Phonegap 1.9, according to a comment on this blog post:

http://richdotnet.blogspot.se/2012/07/create-your-first-phonegap-project-with.html


Set up a Java environment for Cordova/phonegap development on Ubuntu 12.04

published Jun 28, 2013 10:05   by admin ( last modified Jul 10, 2013 02:43 )

Installing Cordova (Phonegap)

I added these to my ~/.bashrc

PATH=$PATH:/path/to/where/i/put/it/adt-bundle-linux-x86-20130522/sdk/platform-tools:/path/to/where/i/put/it/adt-bundle-linux-x86-20130522/sdk/tools
ANDROID_BIN= /path/to/where/i/put/it/adt-bundle-linux-x86-20130522/sdk/platforms/android-17

I'm not saying this is the best way but it worked for me

 ./create /path/to/new/directory com.yourproject yourproject

You must not use spaces in the last part (even within quotes), because then it fails like this:

jorgen@battle:~/workspace/android/phonegap-2.8.0/lib/android$ ./bin/create /home/jorgen/workspace/android/testproject2 net.jorgenmodin.test "A name with spaces in it"
An unexpected error occurred: "$ANDROID_BIN" create project --target $TARGET --path "$PROJECT_PATH" --package $PACKAGE --activity $ACTIVITY &>/dev/null exited with 1
Deleting project...

 

Install Java 7

Download it from Sun, follow the instructions from the highest rated answer on this page: installation - How do I install Oracle Java JDK 7? - Ask Ubuntu

 

But add the following:

 sudo update-alternatives --install "/usr/bin/jar" "jar" "/usr/lib/jvm/jdk1.7.0/bin/jar" 1

I had no jar command, if you already have one it may work however the fastjar program did not understand phonegap's switches so it is not an option.

 



 

Install the JDK


The emulators never launched, with no explanation.

 

You can start an emulator from the command line, by going inside the sdk directory and inside tools and then run

./emulator -avd <emulatorname>

That informed that there was a segmentation fault, and core dumped

By adding the verbose switch, these were the last two lines:

emulator: Initializing hardware OpenGLES emulation support
Segmentation fault (core dumped)

 

So, googling for that leads to this page:

http://stackoverflow.com/questions/13997771/android-emulator-segmentation-fault

 

Which says to do like this

mv tools/lib/libOpenglRender.so tools/lib/libOpenglRender.so.xxx

 

Which then made verything work.

 

Self-signing an apk

If you want to try out your apk on different devices, without connecting them with a USB chord to the development computer, you need to sign the apk. Otherwise it will simply just fail to install. This page shows how to self sign an apk:

Generating Keys - Android Wiki

I used the option

keytool -genkeypair -keystore keystorename -storepass keystorepassword -keyalg RSA \
  -validity $((25 * 365)) -alias keyalias -keysize 2048 \
  -dname "CN=J Random Hacker, O=HackerCo, L=Anytown, ST=Anystate, C=US"

and then

jarsigner -verbose -keystore keystorename apkfilename keyalias 

keytool and jarsigner commands were already installed on the laptop (different from my workstation), it may be different for you. On my workstation I had to do

 sudo update-alternatives --install "/usr/bin/jarsigner" "jar" "/usr/lib/jvm/jdk1.7.0/bin/jarsigner" 1

In Eclipse there is support for signing in the Android Tools context menu.


Thanks for the "until" command in the python debugger

published Jun 28, 2013 03:05   by admin ( last modified Jun 28, 2013 03:05 )

Stepped into a 3000 iteration loop today while debugging python code. How do you get out of that? Turns out there is an "until" command in the debugger that will type next for you until it's about to hit a line further down in the program. Or more precisely:

 

The until command is like next, except it explicitly continues until execution reaches a line in the same function with a line number higher than the current value


Read more: Link - pdb – Interactive Debugger — Python Module of the Week


Seem like udev should be able to detect if power cord is in

published Jun 27, 2013 07:30   by admin ( last modified Jun 27, 2013 07:30 )

Should be worth looking at

 

SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="0", RUN+="/usr/bin/powersave true" SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="1", RUN+="/usr/bin/powersave false"


Read more: Link - Howto: Powersaving tweaks with a udev rule - HOW TO & FAQ Guides - Neowin Forums


Menu for changing text size in jquery mobile

published Jun 27, 2013 05:27   by admin ( last modified Jun 27, 2013 05:27 )

Note to self, this worked grat:
 Link - Edit this Fiddle - jsFiddle


How to re-skin elements that weren't around when jquery mobile skinned

published Jun 27, 2013 04:24   by admin ( last modified Jun 27, 2013 04:24 )

Send a "create" event. I sent ot to the parent element and it works.

 

Normally jQm will enhance elements during the page init event. If you add/remove/manipulate the page after that event has fire you'll need to trigger the enhancement via code. Try adding this line after your append statement. $("#grillaCaps").trigger("create");


Read more: Link - jquery mobile dynamic buttons in grid lose format/style after first “render” - jQuery Forum


Use a merge tool for all merges in Git

published Jun 27, 2013 02:21   by admin ( last modified Jun 27, 2013 02:21 )

A couple of days ago Git decided to automatically merge two branches through, among other things, switching method names between two method bodies (in python). The aggregate result was a mess.

For smaller projects there will not be massive changesets. Is there a way to tell Git to always use a merge tool, even the ones not deemed as a conflict by Git? There seems to be an answer on StackOverflow, define your own configuration version of kdiff3 with the --qall flag set. As I understand the tool always get the option to merge. Untested by me as of yet.

 

if you really want to disable any automatic resolving, just add --qall to the kdiff3 command line above. But then you have to manually resolve all changes in the file manually, even the ones that did not result in a git conflict.


Read more: Link - git - How could I force mergetool GUI (kdiff3) to be always shown? - Stack Overflow


Making a Plone 2.5.5 buildout as of now on Ubuntu 10.4

published Jun 25, 2013 10:55   by admin ( last modified Feb 20, 2015 02:18 )

Also check the newer post: Making a python 2.4 virtualenv buildout on Ubuntu 10.4 & Debian 7 as of 2014-03

I had to make a Plone 2.5.5 buildout today, in order to get the last Plone 2.5 web site of any of my customers up to the Plone 3/4 world. There was some trouble that did not happen half a year ago or so. Here's how to get around it.

Python 2.4

Is still in the repositories for Ubuntu 10.4 LTS. So no problem there. At least.

Virtualenv with site packages

If I used --no-site-packages then the subsequent steps to a functioning buildout would not work, specifically bootstrap.py would go into an infinite "installing distribute loop", so virtualenv must install a local python with access to the 2.4 site packages. Furthermore, with the --setuptools flag, --no-site-packages will make virtualenv (1.4.5) crash on my machine.

Setuptools must also be use instead of distribute. On the slightly older virtualenv I used (1.4.5), with site packages is the default, on newer ones no site packages is the default. So on my older version it's:

virtualenv --setuptools -p python2.4 .

On a newer virtualenv it would probably be:

virtualenv --setuptools --system-site-packages -p python2.4 .

Bootstrap.py with an older zc.buildout specified

With the bootstrap.py script, you can specify a version string

./bin/python bootstrap.py --version 1.4.4

This will give you zc.buildout 1.4.4, which is the recommended old version for those who have problems wth the new version.

Pin Pillow to an older version than current version

If you are using Pillow, the PIL replacement, it cannot be newer than 1.7.8, which is the recommended old version for python 2.4.

Pillow ==1.7.8

...if you pin it in the eggs section,

Pillow =1.7.8

...if you instead pin it in the versions section.

Remove zope libraries in system python2.4

see:

The Donkey's Stone: AttributeError: 'module' object has no attribute 'Surrogate'

 

 

 

 


Some notes on Webview on Android

published Jun 25, 2013 10:16   by admin ( last modified Jun 25, 2013 10:16 )

From the jquery mobile documentation:

 

Android enforces a timeout when loading URLs in a webview which may be too short for your needs. You can change this timeout by editing a Java class generated by the Eclipse plugin for Android:

super.setIntegerProperty("loadUrlTimeoutValue", 60000);

....

Try animation-fill-mode to reduce blinky transitions but beware that we're found that certain devices like the Nexus 7 run animations very slowly when this CSS property is in play. We recommend targeting this carefully and testing thoroughly to ensure that it doesn't impact smoothness. To see how to add this to your CSS, see this commit.


JQuery and Android 2.3, calling a url again gives the cached result

published Jun 23, 2013 03:59   by admin ( last modified Jun 23, 2013 03:59 )

Does a URL always give back the same result? Well according to the standard browser on Android 2.3 it does, at least when using jquery's get method.

I couldn't figure out why the Android 2.3 phone looped over the same old results eventhough the data URL for more new stuff was called anew. It worked well on the laptop and on the Android 4 tablet. It turns out that the 2.3 browser simply thinks that if a url has been called once from javascript, the result is going to be the same on subsequent calls. So it just gives back the old results.

Solution: Add a request number to a dummy request parameter called e.g. "foo":

http://server/more_new_stuff/session_id

becomes:

http://server/more_new_stuff/session_id?foo=1

and foo=2, foo=3, and so on.


Episodes - instrumenting the visitor's browser

published Jun 20, 2013 07:56   by admin ( last modified Jun 20, 2013 07:56 )

...so that you can monitor load times for page, regarding answer from server, time for libraries to load, and whole page.

 

Here are the episodes for this page:


Read more: Link - Episodes Example 1


Some databases

published Jun 20, 2013 02:45   by admin ( last modified Jun 20, 2013 03:16 )

Notes to self.

Tokutek


Tokutek is MongoDB but allegedly with better performance for indexing and some other stuff

The direct benefits include high-performance indexing, strong compression, and performance stability – in other words, the performance stays high, even when data is larger than RAM

 

Read more: Link - Better MongoDB Performance | Tokutek

Hyperleveldb - a faster version of leveldb

Inside HyperLevelDB :: Hacking, Distributed

Ardb

Ardb, uses Redis protocol for accessing some fast databases, mostly leveldb.

Ardb is a BSD licensed, redis-protocol compatible persistent storage server, it support different storage engines. Currently LevelDB/KyotoCabinet/LMDB are supported, but only LevelDB engine is well tested.
 

KDr2/redis

Another one that does the same for leveldb only:

KDr2/redis-leveldb · GitHub

 


What Apache means with "The time taken to serve the request"

published Jun 15, 2013 05:10   by admin ( last modified Jun 18, 2013 12:23 )

I take it in good faith that this guy knows what he's talking about.

 

%D logs the time between Apache starting to process a request (i.e. I believe it omits the handshake) and offloading it completely onto the local TCP stack.


Read more: Link - apache2 - The time taken to serve the request? - Server Fault


Get an element to stay fixed on scroll on the Android 2.3 browser

published Jun 14, 2013 02:31   by admin ( last modified Jun 14, 2013 02:31 )

The page must not be zoomable.

 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
 

 



Read more: Link - html - How to disable web page zooming/scaling on Android? - Stack Overflow


How to use single quotes in a perl one-liner

published Jun 14, 2013 01:23   by admin ( last modified Jun 14, 2013 01:23 )

Use the octal form, i.e. \047 .

 

echo "a,b" | perl -F',' -lane 'print "$F[0]\047";' a'


Read more: Link - shell - Perl one-liner with single quote - Stack Overflow