28 Nov 2014The Dropbox app on my Android offers to automatically save pictures I take to my Dropbox account. That is a very great feature, removing the pain of doing backup of pictures on a regular basis.
But it actually saves them in a special Dropbox folder named Camera Uploads
, one that cannot be moved, and is not synchronized with the desktop Dropbox.
So I create a special ifttt recipe that will copy any new picture added to this folder into a real Dropbox folder. I simply chose Dropbox as the input, with /Camera Uploads
as the folder to listen to. Then I also chose Dropbox as the ouput, as the File URL,
as the File name, and chose one of my folders for the Dropbox path folder.
Now, whenever I take a picture on my phone, it gets saved on my Dropbox account, and then ifttt kicks in and copy it to another directory in my Dropbox which will in turn save it on my local Dropbox folder.
That's quite circumvoluted to simply save a picture from my phone to my computer, but that's still the easiest way I found.
27 Nov 2014Today, I needed to test a file upload mechanism, and needed a bunch of different files, to be able to test that the max file size, max/min file dimensions and image type where correctly checked.
I asked my good friend the command line and came up with the following command to generate the needed files.
$ dd if=/dev/urandom of=1mo.binary count=1024 bs=1024
1024+0 records in
1024+0 records out
1048576 bytes (1,0 MB) copied, 0,0684895 s, 15,3 MB/s
$ ls
total 1,1M
-rw-r--r-- 1 tca tca 1,0M nov. 27 12:00 1mo.binary
This created a 1mo.binary
binary file of exactly 1Mo. That can be useful if you simply need to test size limits. But I also needed my files to be valid jpg files. So I used convert
.
$ convert -size 640x640 xc:blue 640.jpg
$ ls
total 12K
-rw-r--r-- 1 tca tca 2,7K nov. 27 12:04 640.jpg
This created a valid blue jpg file of 600x600 px. But the file size was way to small, and I simply needed to have bigger filesize but not bigger file dimensions. Best way to do it was to add crappy metadata that will simply adds to the filesize. So I used /dev/urandom
again to get random data.
$ cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 1048576 | head -n 1 > 1mo.txt
$ ls
total 1,1M
-rw-r--r-- 1 tca tca 1,1M nov. 27 12:04 1mo.txt
-rw-r--r-- 1 tca tca 2,7K nov. 27 12:04 640.jpg
This generated a 1mo.txt
file of random alphanumeric garbage. You can change the fold -w
value to increase the size of the generated file. Next step was to feed this value to our jpg file.
$ exiftool 640.jpg -comment\<=1mo.txt
$ ls
total 2,1M
-rw-r--r-- 1 tca tca 1,1M nov. 27 12:04 1mo.txt
-rw-r--r-- 1 tca tca 1,1M nov. 27 12:05 640.jpg
This updated the 640.jpg
file by adding the content of 1mo.txt
into the comment
metadata. You need to use the <=
syntax to feed it the content of the file because your shell might not like having a 1Mo argument. Also, you need to escape the <
or your shell will try to interpret it.
Now you're ready to generate jpg files of any dimensions and any filesize.
23 Nov 2014I'm using git for all my workflow. I use either GitHub or BitBucket to store my code online. And for some tiny projects, I'm also using git directly to push in production.
Pushing to own remote
I have a few repositories that simply holds a bunch of html
and css
files, to display a very simple page. Whenever I push some changes to thoses repositories, I want to have the changes directly reflected online.
For this I created on my server a new repo, aptly named repo
. In repo
, I simply ran git init --bare
to create a bare repository. Now, from my local repository I just update my local git repository to point the origin
remote to this bare repository. Running git push
pushed my changes to this repo.
Easy, I have my own repo on my own server to store my files.
Pushing to production
But that's only a bare repo, holding the list of changes but not exposing the working directory. For that, I cloned repo
into another directory using git clone ./repo ./dist
. This dist
directory is actually served by nginx.
I added a hook to repo/hook/post-receive
with the following code :
#!/bin/sh
unset GIT_DIR
cd /path/to/my/dist/directory
git pull
This will ran everytime the repo
receives a new push. It will go to the dist
folder and pull changes from repo
(as repo
is the default origin for dist
as we cloned from it).
The part about unset GIT_DIR
is needed so that the hook correctly run in a bare repo.
Now, everytime I push my code, the hook will be run and the dist
repo will be updated. And as this directory is exposed through nginx, it will be directly available to all.
Pushing to multiple remotes
But that's not finished yet. I don't like having my code saved only in one place. I'd like to also have my sources available on GitHub. So I updated the post-receive
hook by adding the following lines :
cd /path/to/my/repo/directory
git push
Of course, I also configured my origin
remote to be GitHub, but you can make it any repo. This will automatically push the content to a secondary repo whenever the primary one receives new data.
Conclusion
With simple git hooks I managed to push my code to production and save the source in two different repository whenever I git push
. Less commands to type, more time to code something else.
17 Sep 2014Because I'm living in France, all my computers have a standard French keyboard layout. It is based on the azerty layout, with all the frequent French characters in easy access (eg: é
, è
, à
, etc).
It is different from a classical qwerty layout in various ways, the most notable being that the numbers on the number rows are activated by pressing Shift. On a classical qwerty keyboard, pressing the 2
key will issue a 2
. In my case it will issue a é
. I need to press Shift+2 to get a 2
. And AltGr+2 gets me a ~
.
Why am I talking about that ? Because I'm also a developer, and I write code everyday. And code is not like prose, the characters with special meanings are not the same. We use and abuse (
, {
, ;
, -
, _
or [
. Some of these characters I use very often, and due to my keyboard layout, I often need to press Shift or AltGr to get the needed char.
This, of course, struck me as not very productive. There has to be a better way. So I dig up a bit and found xmodmap
that is used by linux to bind a keycode to a keysym. A keycode is what is send to your OS when you press one of your plastic keys on your keyboard. One physical key on the keyboard equals to a keycode. Each keycode can have one or several modifiers (like Shift, Control or AltGr). And each of combination of keycode + modifier(s) equals one keysym, which usually translate to a character, but can sometime have special meaning (like Return, Backspace or the F keys).
With xmodmap
, you can manually configure which keycode sends which keysym. So I've updated my own xmodmap
to move some of the special chars I use often to place I can access easily without having to move my hands too much.
To do that, I mostly took advantage of the AltGr
modifier that is currently underused. This modifier is mostly applied to the number row (and pressing AltGr
and anything on the number row is not the easiest thing to do).
The most important change I made is to add AltGr+i
to create a -
(dash) and AltGr+o
to create a _
(underscore). Those two chars are overused when coding, and having them on those keys allowed me to type them much much faster without having to move my hand on the keyboard.
The others little changes I made were to add AltGr+h
as #
(hash, the mnemonic is that a capital H looks a bit like a #
). Following the same idea I put the pipe |
on AltGr+j
. I also put \
on AltGr+u
. These are keys easily accessible and I use them often.
Finally, the last two important bindings are AltGr+r
to produce a `
. The default French keyboard layout does not have a key for the backtick, so creating mine was a huge timesaver. The last one is AltGr+q
to get a ~
(tilde).
I also tried to put [
and ]
respectively on AltGr+k
and AltGr+l
but I never use them.
You find below the xmodmap
I use. Put it in a ~/.xmodmaprc
file and run setxkbmap fr && xmodmap ~/.xmodmaprc
to apply them.
keycode 27 = r R r R grave
keycode 30 = u U u U backslash
keycode 31 = i I i I minus
keycode 32 = o O o O underscore
keycode 38 = q Q q Q asciitilde
keycode 43 = h H h H numbersign
keycode 44 = j J j J bar
keycode 45 = k K k K bracketleft parenleft
keycode 46 = l L l L bracketright parenright
As I recently had to work on a Windows machine, I installed AutoHotKey and created this little script to emulate the same shortcuts :
<^>!r::Send ``{Space}
<^>!u::Send \
<^>!i::Send -
<^>!o::Send _
<^>!q::Send `~{Space}
<^>!h::Send {#}
<^>!j::Send |
This little changes were a huge timesave for me, hope they gave you some ideas too.
16 Sep 2014I'm currently forced to develop on Windows. And it hurts. I feel like a clockmaker forced to work with gloves and blindfolded. I keep hitting strange and weird Windows limitations that are real productivity killers.
The most recent was not being able to delete a folder because its filename was too long. Wait, what ? As soon as you start using npm
and download a bit of modules, you'll most certainly end up with a node_modules
folder that's too long for Windows to handle.
But npm
is clever, and it can circumvent this limitation. So, whenever you want to delete a node_modules
folder and Windows won't let you do it, use npm
. Update your package.json
to remove every element in dependencies
and devDependencies
and run npm prune
. This will empty your node_modules
folder.
You're welcome.