Archives 2005 - 2019

git pull --all does not update HEAD for the branches you're not on

published Jun 16, 2015 03:50   by admin ( last modified Jul 21, 2015 11:04 )

Summary

To merge in changes from "other_branch", do this:

git pull --all
git merge origin/other_branch

Longer story

I continuously need to merge in changes from a branch that I have branched off of. Sometimes I do it by switching over to that branch locally, do a pull, and then switch back to mine and do a

git merge other_branch

That works fine. But sometimes I have tried to remain on my branch and do a

git pull --all

followed by a a

git merge other_branch

But that won't work! Why?

"git pull --all" does indeed fetch all tracked remotes and updates them, but only merges new updates locally on your current branch. So even if other branches are updated locally, HEAD hasn't moved in them and from merge's point of view the updates aren't there.

This ought to solve the problem:

git merge origin/other_branch

currently untested by me.

Update: Now tested by me. It doesn't work.... unless you pull first! So this is the way it should look:

git pull --all
git merge origin/other_branch

Reusing argument passed to a bash script

published Jun 01, 2015 11:49   by admin ( last modified Jun 01, 2015 11:49 )

Use $@ . This is magical and will work. Not sure how it is magical, but it is. Put double quotes around it.

 

For passing the arguments to the inner command "$@" -- with the double-quotes, $@ preserves the original word breaks, meaning that the inner command receives exactly the same argument list that your script did.


Read more: Link - linux - Preserve Quotes in bash arguments - Stack Overflow


Getting all text from pages in a Plone server

published Jun 01, 2015 03:30   by admin ( last modified Jun 01, 2015 03:32 )

Start server with the debug sub command. "app" is root of the Zope server. In my case my plone site is called "site". So I assigned app.site to the variable "site". The pages are in Archetypes, with a UID method for each.

 

>>> res = site.portal_catalog(portal_type='Document')
>>> res.actual_result_count
2513
>>> res[0]
<Products.ZCatalog.Catalog.mybrains object at 0xb31020c>
>>> res[0]['Title']
'Some databases'
>>> res[0].getObject().SearchableText()
'Link---Better-MongoDB-Performance---Tokutek  Some databases   \r\n\tNotes to self. \r\n \r\n\tTokutek \r\n \r\n\t \r\n\tTokutek is MongoDB but allegedly with better performance for indexing and some other stuff \r\n \r\n\tThe direct benefits include high-performance indexing, strong compression, and performance stability \xe2\x80\x93 in other words, the performance stays high, even when data is larger than RAM \r\n \r\n\t\xc2\xa0 \r\n \r\n\tRead more:  Link - Better MongoDB Performance | Tokutek  \r\n \r\n\tHyperleveldb - a faster version of leveldb \r\n \r\n\t Inside HyperLevelDB :: Hacking, Distributed  \r\n \r\n\tArdb \r\n \r\n\tArdb, uses Redis protocol for accessing some fast databases, mostly leveldb. \r\n \r\n\t 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.  \r\n\t\xc2\xa0 \r\n \r\n\tKDr2/redis \r\n \r\n\tAnother one that does the same for leveldb only: \r\n \r\n\t KDr2/redis-leveldb \xc2\xb7 GitHub  \r\n \r\n\t\xc2\xa0 \r\n '
>>> res[0].getObject().UID
<bound method ATDocument.UID of <ATDocument at /site/index_html/Link---Better-MongoDB-Performance---Tokutek>>
>>> res[0].getObject().UID()
'0b933c2f07cb4e81a36b410429fe4e50'
>>> docs = [(doc.getObject().UID(), doc.getObject().SearchableText()) for doc in res]


Some backup & synchronization solutions

published Jun 01, 2015 02:20   by admin ( last modified Jul 21, 2015 11:07 )

SparkleShare - Self hosted, instant, secure file sync

Seafile - Open Source Cloud Storage for your teams and organizations

Code42 CrashPlan - Endpoint Backup + Restore

Obnam


Firefox comparatively good at storing passwords securely

published May 31, 2015 02:02   by admin ( last modified May 31, 2015 02:02 )

If you use a good master password. Google Chrome and Internet Explorer were worse at it on Windows, according to the below linked article:

 

However, it would be unfair to end the post saying that browsers are completely unreliable at storing passwords. For example, in the case of Firefox, if a strong Master Password is chosen, account details are very unlikely to be harvested.


Read more: Link - RaiderSec: How Browsers Store Your Passwords (and Why You Shouldn't Let Them)


How many threads are running in my python application?

published May 30, 2015 10:45   by admin ( last modified May 31, 2015 08:00 )

You can ask the threading package about that:

threading.active_count()

 

Not sure why I got 7 though.


When you want a cheap short-throw linear actuator

published May 30, 2015 10:35   by admin ( last modified May 30, 2015 10:37 )

You are probably looking for a solenoid. If one searches for linear actuators on the other hand, things are going to be expensive.

 

Solenoid - 5v (small) - ROB-11015 - SparkFun Electronics


How to trace a thread in python

published May 29, 2015 02:10   by admin ( last modified May 30, 2015 10:38 )

I noticed that a thread in a python application that I am debugging, did not turn up in the trace print. Turns out there is a special settrace call you make from the threading package. I linked below to python 3 but it works in python 2.7 as well.

threading.settrace(thread_traceit)

17.1. threading — Thread-based parallelism — Python 3.4.3 documentation


A possible way to handle unicode stealth

published May 27, 2015 09:05   by admin ( last modified May 27, 2015 09:06 )

I haven't tried this so I do not know if it is in any way practical, but wouldn't it be possible to classify texts as being in one language? If so, you could filter out any characters or glyph combinations that aren't native to that language.

It would be a bit like how markup languages such as Markdown, reStructuredText, Creole and others have largely supplanted HTML for creating rich text documents on Wikipedia, GitHub, in python documentation and many other places.

 

Its pretty easy to have two different Unicode strings display identical output - and that can cause a whole host of problems. For instance, many family friendly sites may ban foul language from user comments, but its trivial to come up with Unicode equivalent strings that bypass any blacklist of obscene language.


Read more: Link - Unicode is Kind of Insane


Terminating a process and its subprocesses from python

published May 22, 2015 12:45   by admin ( last modified May 22, 2015 12:50 )

I'm testing a python server from a python test script. The server reads a config file on startup and I want to test that it actually works. So I want the script to test the server as if it were run from the command line. When run from the command line, the server can be terminated by typing Ctrl-c.

The server starts a child process from inside itself. Problem is, if I start the server with subprocess, and then send the kill/terminate signal to it via subprocess, the server's child process keeps running.

The trick is to assign a new process group to the server, separate from the testing script. In this way the os module can issue a "killpg" command that takes care of terminating the server and its child processes, without killing the testing script.

import subprocess
import os
import signal

p=subprocess.Popen(your_command, preexec_fn=os.setsid, shell=True) 
os.killpg(os.getpgid(p.pid), signal.SIGTERM) 



Found this solution on Stackoverflow:

To handle the general problem:
p=subprocess.Popen(your_command, preexec_fn=os.setsid) 
os.killpg(os.getpgid(p.pid), 15) 
setsid will run the program in a new session, thus assigning a new process group to it and its children. calling os.killpg on it thus won't bring down your own python process also.


Read more: Link - unix - Killing a subprocess including its children from python - Stack Overflow


Big wars may be in our future

published May 18, 2015 03:20   by admin ( last modified May 25, 2015 11:46 )

It has been common to assume that man's lot in the world is getting better and better, and that one of the things contributing to this, is less and less death caused by war.

However if you note and measure that the distribution of deaths from war through history is seriously fat-tailed (which means that very rarely occuring wars do kill a whole lot of people), then almost all measurements you will take on the way will be below the true mean. And we may in fact be up for serious mayhem. This is presented in a paper (linked at the end of this post) by Nassim Nicholas Taleb and Pasquale Cirillo, and blogged about by Mark Buchanan here:

Violent warfare is on the wane, right? — Bull Market — Medium -

For example, it turns out that, for a process following this statistical pattern, one should expect fully 96% of all observations to fall below the true mean of the process. This brings home just how non-Gaussian and non-normal this process is. We’re used to thinking that, if we observe instances from some random process, we ought to (very crudely) see events about half above and half below the mean. Instead, in this process, one should expect that almost all observations will be below, and even far below, the actual mean. We almost always see fewer wars than we, in a sense, should.

Original paper: http://www.fooledbyrandomness.com/violence.pdf


Why devices interface to Android via the headset jack

published May 17, 2015 05:51   by admin ( last modified May 17, 2015 05:51 )

It seems that more and more devices interface with Android phones and tablets via the headset jack. As examples here is a brand new geiger counter: http://www.kjell.com/sortiment/telefoni-kommunikation/mobiltelefon-tillbehor/gadgets/geiger-och-uv-matare/geigermatare-for-mobilen-p96153#ProductDetailedInformation

And here is the new credit card processing unit for iZettle (the older one uses Bluetooth). https://www.izettle.com/se/card-readers

I have used the IZettle bluetooth device with different devices and it just doesn't work on all devices, due to as far as i understand different bluetooth stacks.

I recently tried to interface to an Arduino with a USB library through an OTG . It worked on one phone but not on the other.

My guess is why this is happening is that the implementations for Bluetooth and USB support on Android are too buggy or at least diverging in standards.

We do know however that people have standards for music and sound quality, which the manufacturers must abide too or people won't use the product at all. So we are sometimes back to analog modem signals it seems.


Current transformers cannot measure cables with returning current in them also

published May 13, 2015 06:55   by admin ( last modified May 13, 2015 06:59 )

Kind of obvious, but it means you cannot just clip them around a normal power cable, such as are used to power household devices that plug into wall sockets.

 

The primary winding of the CT is the wire carrying the current you want to measure. If you clip your CT around a two or three core cable that has wires carrying the same current but in opposite directions, the magnetic fields created by the two wires are equal and opposite and will cancel each other. Your CT will have no output


Read more: Link - CT sensors - Introduction | OpenEnergyMonitor


ESP8266 - WiFi chip that can be a full microcontroller

published May 12, 2015 12:45   by admin ( last modified May 12, 2015 01:56 )

Including kind of compatible with Arduino. It obviously can do WiFi, but people have now hacked so that you do not need a microcontroller or computer to control it. It can do that by itself, including accepting a lot of Arduino code. ESP8266 Community Forum View topic - Arduino IDE released for ESP8266

This board exposes all the pins, including serial and PWM MOD-WIFI-ESP8266-DEV - Open Source Hardware Board

Lua based firmware nodemcu/nodemcu-firmware

Read more: Link - ESP8266: This $5 Microcontroller with Wi-Fi is now Arduino-Compatible | Make:


Arduino-like cards with built in Bluetooth

published May 11, 2015 12:35   by admin ( last modified May 15, 2015 12:08 )

 

Summary: LightBlue Bean by Punch Through Design seems the most promising.

All cards untested by me at this point in time.

It seems to me that a good use case for the Arduino is as a very low power device that just wakes up briefly, to send some sensor data to a server. Sensor data could be different air quality measurements such as humidity, or certain gases. As long as the bluetooth can connect relatively quickly on wake-up, you ought to be able to make sensoring arduinos that can last for years on a battery. So you could place them in places that are difficult to reach with electrical power.

 

Here is what I have found after a brief search, and as I said I have not tested any of these:

Bluetooth Bee - Standalone (built-in Arduino) - priced at $23.50 when I read the link, needs a shield in order to be programmed, it seems

RF Digital RFduino RFD22102 - Micro Center - at $21, needs an additional USB shield in order to be programmed

BLEduino: Bluetooth 4.0 Made Easy  has a USB port, which might make it less power efficient. Does not seem to be publically available to buy just yet.

Bluz: A cloud-connected, Bluetooth LE development kit by Ben Harris — Kickstarter

At least according to specs, this seems to be what I am looking for: LightBlue Bean – Punch Through Design. It says:

The Bean is the first Arduino-compatible microcontroller board that's wirelessly programmable over Bluetooth Low Energy.

It costs $30 though, so a bit more pricey that the options above. I had to get deep into Google's search results to find LightBlue Bean.

I wonder why the other ones cannot just be programmed on serial pins? Have I missed something?


Free high quality audio recording on Android

published May 11, 2015 07:35   by admin ( last modified May 11, 2015 09:24 )

Conclusion

Hertz the WAV recorder, Record That Note and PCM Recorder had the best recording quality.

  • Hertz is open source and stays on my phone.
  • Record that note has a VU meter which is quite useful, and you can play and share sound files from the app so it might also stay on my phone.

The contestants

The 6 free apps below for Android claim to record high quality audio in uncompressed form such as WAV or PCM. Apps only briefly tested by me at this point in time, with an LG G2 with its factory headset, and me counting to twenty. Lots of white noise in all recordings and no possibility to adjust recording levels.

  • Hertz, the WAV recorder Hertz is open source software licenced under Apache 2.0. The source code is available, not that many downloads, sounds better than Urecord I think in a crude preliminary test
  • Urecord - Urecord is open-source via the GPL: https://bitbucket.org/thomasebell/urecord, not that many downloads, sounds a bit worse than the other ones I think (or imagine).
  • Sound Recorder + , not that many downloads, only one to go up to 48 KHz (the other ones go to 44.1 KHz) good sound quality, but it skipped samples at 48 KHz so that a whole number is missing in my recording test of counting to twenty. I have not tested with lower sampling frequencies, but I will not use this app.
  • Record That Note Can delete silence (not what I am looking for but can be good for those who want to cut out pauses automatically), not that many downloads, sounds on par with Hertz I think in a crude preliminary test
  • PCM Recorder, 8k downloads, sounds on par with Hertz I think in a crude preliminary test
  • Recordoid Dictaphone Lite Claims high audio quality, does not specify format, 1,6K downloads, wants rights to send SMS, there may be a point to the SMS permission, but I'm avoiding the app

The apps where found through this useful page: 10 Best Apps for Uncompressed Audio (android) | AppCrawlr

 

A better microphone is the obvious upgrade from here. I wonder if the noise comes from the phone or the mic+wire. Furthermore, if the noise is generated by atmospheric noise, would it be possible to mix in a real time noise source in anti phase? Would a low impedance output amplifier help between the mic and phone?

 


Power consumption of the Raspberry Pi Model B & B+ & an Arduino Uno R3

published May 09, 2015 11:50   by admin ( last modified May 11, 2015 09:59 )



A lightly-loaded model B with keyboard = 1.89 W -> daily 45.36 Wh
A lightly-loaded model B+ with keyboard = 1.21 W -> daily 29.04 Wh
B+ with LAN/USB chip off (no i/o except GPIO) = 0.76 W -> daily 18.24 Wh B+ shut down = 0.26 W -> daily 6.24 Wh
The B+ really offers huge improvements in the power circuitry. Wow!

For an Arduino Uno it seems to be around 230 mW at idle, and putting it to sleep helps a bit mut not that much since the USB is still running it seems, so about a 25% saving only.

It seems that a Raspberry pi B+ can compete with an Arduino Uno in idle in terms of power consumption. You've got to get one of the Arduinos without USB to get to the real low power stuff.
 

Read more: Link - power supply - How much energy does the raspberry pi consume in a day? - Raspberry Pi Stack Exchange

 

How Much Less Power does the Raspberry Pi B+ use than the old model B? » RasPi.TV

Arduino Power Consumption - Gadget Makers' Blog


Controlling a servo with the phone's headset jack

published May 09, 2015 01:25   by admin ( last modified May 09, 2015 01:25 )

Untested by me, but could potentially cut down on the number of components.

 

Controlling a hobby servomotor is relatively easy. It requires a single digital pulse-width modulation (PWM) signal at 50Hz, which means one pulse every 20ms. The width of the “high” pulse sets the absolute rotation angle of the servo.


Read more: Link - Smartphone Servo | Make:



Like RPi but with WiFi, Bluetooth and charging circuitry <$10

published May 08, 2015 11:50   by admin ( last modified May 31, 2015 08:01 )

A Kickstarter  project. This seem to be aimed at the Raspberry Pi market. A bit worse specs than the Raspberry Pi 2 but similar to the Raspberry Pi B+. Circuitry handling batteries is a boon, and so is built in bluetooth and Wifi .

 

Differentiating Chip from Beagle is its built-in WiFi, Bluetooth, and the ease in which it can be made portable, thanks to circuitry that handles battery operation.


Read more: Link - The World's First $9 Computer Coming to Kickstarter | Make: