Taking Webcam Photos Via the Command LineHere's an easy way to use your default webcam to take a photo with a single command from a terminal:
mplayer -vo png -frames 1 tv://
I wanted a quick and easy way to take a photo with my laptop's webcam and upload it to my server on a regular basis when I'm away from my machine. Side note: this wasn't to take photos of unknowing human victims, but to check in on my dogs :).
I realized that the first few frames weren't great due to the camera turning on, so I had it take 5 frames:
mplayer -vo png -frames 5 tv://
I then wanted to upload them to my server to be accessible (behind nginx's basic authentication so only those with the credentials can see them):
mplayer -vo png -frames 5 tv://; \ scp 00000005.png magnatecha.com:~/webroot/mydomain.com/cam/pic.png;
I also wanted to take the webcam photo on an interval:
while true; do \ mplayer -vo png -frames 5 tv://; \ scp 00000005.png magnatecha.com:~/webroot/mydomain.com/cam/pic.png; \ sleep 120; \ done;
That creates an infinite loop that takes 5 frames of photos, uploads the fifth one to my server, waits 120 seconds and then does it all again. This allows me to see a photo of whatever my laptop is pointed at that is at most 2 minutes old.
Screenshot Sharing Script for Mac OS
I recently wanted to move away from commercial screenshot sharing tools (I was using Jing), so I decided to create a script that takes screenshots, allows you to annotate them, then uploads them to a free webhost. The free host I use is 000webhost.com and I use ftp to upload the image. Here's the script:
#! /bin/bash d=`date +%Y%m%d%I%M%S` host="http://tr99.host56.com/" password="*******" screencapture -i $d".png"; open $d".png" #edit? read go; echo "put "$d.png | ftp ftp://a8533349:$email@example.com:21/public_html/ \ && echo $host"$d.png" | pbcopy mv $d.png ~/pics/
That will take an interactive screenshot, open it in Preview so that you can edit and save it, then continue and upload it to your ftp host when you press any key in the terminal. I have my terminal (iTerm2) set to hide with a keyboard combo (ctrl+space) so that I can tell it to get out of the way if I'm taking a screenshot of something else. I assigned the script to a bash alias, so all I have to to do is open a terminal and type my alias. It also copies the url to the screenshot to your clipboard using pbcopy so that you can just paste it when you want to share it.
Get a random file from a directory with the Linux terminalHere's how you can grab a random file from a directory using the GNU/Linux terminal:
ls | shuf -n 1
And perhaps you want to do something like open that file with a program:
your_program `ls | shuf -n 1`
I used this to do things like open a random image with feh from my pictures folder:
cd Pictures; feh `ls | shuf -n 1`
The magic here is the
shuf command that will output
n pseudorandom items from a collection that is fed to it.
Nginx and “413: Entity too large.”That's what she said! Okay, okay, here's how to fix an "entity too large" error with nginx. Add this to your server block:
10M is the size of uploads you want to allow. The default is 2 MB, but as you know people have smartphones that take larger pictures than that now. Just remember you should probably resize them for web display until we all have better download speeds.
SQLite 3 and PHP: "unable to open database file"While playing with SQLite 3 and PHP, I encountered an oddity: the SQLite database file must be writable AND be in a writable directory. So if you're running SQLite commands from within a PHP web page, the directory your database is in and the database itself must be writable by your www user. With most GNU/Linux distros, this would take care of it:
sudo chown yourusername:www-data -R /path/to/db
sudo chmod 775 -R /path/to/db/yourdb.db
I wouldn't advise working directly in your home folder or changing its permissions/ownership, though.