Friday, April 3, 2015

Restore Apps to Their Original Layout

Let's say you have too many folders in the iPhone and you have forgot what's inside all of them, or accidentally someone (i.e. your kid) move the applications around the home screen, or you want to cleanup your iPhone or simply you want a fresh start. One way to do this is to restore all the Apple native applications to the original layout and move out all the apps from their folders and put them all in the home screen sorted alphabetically, filling as many screens as necessary.

Just go to: Settings -> General -> Reset -> Reset Home Screen Layout.

Be careful in this menu, there are many resets and you don't want to reset something else you don't want. Also, the folders will be deleted but not the applications inside.

Enjoy your sorting and cleanup!!

Monday, March 16, 2015

Create a Recent Items Stack in the Dock

If you want a stack in the Dock with the most recently accessed files or apps, open Terminal and type the following command:

defaults write com.apple.dock persistent-others -array-add '{ "title-data" = { "list-type" = 1; }; "title-type" = recents-tile"; }'

The restart the Dock with:

killall Dock

When the Dock reappears, you will see a stack with the recent items besides the Trash. You can change which items to show such as applications, documents, servers, etc... by right-click on the stack and select the desired items to show.

Tuesday, March 10, 2015

Para crear un Screencast

Leyendo una revista de "Cuardernos Mac" encontré un articulo de como crear un screencast y del cual quiero guardar y compartir algunos consejos y notas importantes.

Consejos:

  • Informarse primero antes de comunicar. No deberíamos de comunicar una información falsa o incorrecta.
  • Anota un resumen de guión o palabras claves para no olvidar nada. No es escribir todo el texto a informar y leerlo, la idea es tener una guía.
  • Familiarizate con la herramienta antes de hacer una grabación para ser publicada.
  • Trabaja en un lugar tranquilo, donde estés solo y sin interrupciones.
  • Tomate el tiempo que necesites. Haz una pausa antes de grabar para que tu voz suene calmada. Respira profundo.
  • Si no estas satisfecho, vuelve a empezar pero si no estas al 100% mejor déjalo para otro día.
  • Es normal cometer errores mientras grabas. Palabras mal pronunciadas, que te trabas, etc... El screencast no tiene porque ser perfecto.
  • Tratar de ser dinámico y entretenido. A no ser que estés haciendo un screencast para dormir. :)
  • Intenta abreviar, es mejor dividir el screencast. Un screencast, un tema. No es recomendable pasarse de los 10 minutos.

Preparación:

  • Verifica que el sonido funciona. Has una prueba para ver que se esta grabando.
  • Ajusta el sonido para que se escuche correctamente.

Añadir un titulo:

  • Utiliza un programa de diseño como: Gimp, Photoshop o Keynote. Puede haber mas, incluso algunos dedicados para screencasts.
  • Incluye un fondo, titulo y guarda el archivo como imagen. Asegurate de que tiene el mismo tamaño en pixeles.
  • No crees una secuencia de mas de 10 segundos para el titulo. Si es posible, no incluyas efectos especiales "pesados", los que ven el screencast lo ven por la información, no por el titulo.
  • Guarda los elementos originales: titulo, screencast original y screencast terminado.

Herramientas

Aunque pueden existir varias la que conozco y veo que recomiendan es Screencast. Si hay alguna mejor, por favor, deja un comentario.

Fuente

Revista "Cuadernos Mac" numero 6 en Español. Articulo: "Como crear un screencast, paso a paso" por Audrey Couleau.

Thursday, February 19, 2015

Console Keyboard Shortcuts

I use to forget some keyboard shortcuts working on the UNIX console or Mac OS X Terminal. So, I create this cheat sheet to remember them and I hope can be useful for you too.

KeyUsed for
Ctrl PSame as Up Arrow
Ctrl NSame as Down Arrow
Ctrl BSame as Left Arrow
Ctrl FSame as Right Arrow
Ctrl MSame as Enter
Ctrl AGo to Beginning of the line
Ctrl EGo to End of the line
Ctrl WDelete previous word
Alt LLowercase the word from where the cursor is to the end of the word
Alt UUppercase the word from where the cursor is to the end of the word
Alt CCapitalize letter where the cursor is and move the cursor to the end of the word
Ctrl TTranspose/Switch the letter where the cursor is by the the previous letter
Alt TTranspose/Switch the word where the cursor is by the the previous word
Ctrl KCut from the cursor to the end of line
Alt DCut from the cursor to the end of the word
Ctrl UCut from the cursor to the beginning of line
Alt BackspaceCut from the cursor to the beginning of the word
Ctrl YPaste what was cut
Ctrl RReverse search. Search in previous commands.
Ctrl LClean screen

Wednesday, September 3, 2014

Initial setups to Raspberry Pi


There are tons of documentation about how to setup the Raspberry Pi in many different ways, so I decide to document what I have done to setup my Raspberry Pi, just in case I break it and have to rebuild it. In this setup the mouse is not needed and by the end of it you won't need the keyboard neither the network cable, so you'll have one USB port available (in the other is the WiFi Dongle) because you'll be accessing your Raspberry Pi from you Mac in different ways.

These settings are:
  1. Install Raspbian
  2. VNC Access
  3. Setup WiFi
  4. SSH Access
  5. Sharing Files and Share Screen to a Mac with AFP
  6. Sharing Files with Samba
  7. Access form iPad or iPhone
All these instructions were made with a Mac and to connect to the Raspberry PI from a Mac. The instructions for Windows or Linux are different, so check the source pages if you are not using Mac OS.

What do you need?

  • Raspberry Pi (This was tested with a Raspberry Pi Model B)
  • Mac (I'm using OS X 10.9.4)
  • Internet connection
  • Wi-Fi Dongle (I'm using an Edimax EW-7811Un)
  • Network cable
  • HDMI Cable
  • Keyboard
  • Mini SD Memory Card 8GB with SD Card Adapter
A Mouse is not required but if you need it I recommend to use a USB Hub to connect all the devices or a Logitech Wireless Mouse and Keyboard with a Unifying USB receiver (like this one). Just make sure to pair both devices to the Unifying USB receiver in other computer (Mac or Windows).



Install Raspbian


The easy way is to install Raspbian with NOOBS but you can also download the image and install it in the SD card.
  1. Download NOOBS from http://downloads.raspberrypi.org/NOOBS_latest
  2. Format the SD card:
    1. Identify the disk ID with Utility Disk. Select the SD card and press Cmd+I, in the Disk Identifier there is a value diskN, where the number N is the disk ID. Or, using the command line with the diskutil command to get the value of N (get N from diskN not diskNsM):
    2. diskutil list
      
    3. Format the SD card with FAT 32 using Utility Disk. Select the SD card and click on Erase tab, select MS-DOS (FAT) in Format, write the disk name - I use RASBERRYPI - and click on the Erase button. Or, using the command line with the diskutil command replacing the N by the disk ID of your SD card:
    4. diskutil eraseDisk FAT32 RASPBERRYPI /dev/diskN
      
  3. Copy the zip file to the SD Card already formatted with FAT32:
  4. cd /Volumes/RASPBERRYPI/
    cp ~/Downloads/NOOBS_v1_3_9.zip .
    
  5. Unzip the NOOBS file from the SD Card:
  6. unzip NOOBS_v1_3_9.zip
    cd
    diskutil eject /dev/diskN
    
  7. Insert the SD Card to the Raspberry Pi, hook up everything (keyboard, network cable, HDMI and power supply). A mouse is not required.
  8. Select Raspbian
  9. Press l and select English (US)
  10. Press i to install it and wait.

The install image way is:
  1. Download the Raspbian image from http://downloads.raspberrypi.org/raspbian_latest and unzip the downloaded file.
  2. wget -O raspbian_latest.zip http://downloads.raspberrypi.org/raspbian_latest
    unzip raspbian_latest.zip
    
  3. Format the SD card as explained above.
  4. Unmount the SD Card with Disk Util by selecting the disk and click on Unmount at the top. Or, using the command diskutil:
  5. diskutil unmountDisk /dev/diskN
    
  6. Install the image with dd command replacing N by the disk ID of the SD card and the name of the img file.
  7. sudo dd bs=1m if=raspbian.img of=/dev/diskN
    
  8. Insert the SD card, hook up keyboard, network cable, HDMI and the power supply. You will not need a mouse.

Once Raspbian is installed and boot the Raspberry Pi Software Configuration Tool (raspi-config) will start:
  1. Select option #1 Expand Filesystem to ensure the SD card is being used properly.
  2. Do not change password of the pi user now, the default is raspberry.
  3. Select what to see when the Raspberry Pi boot: the Desktop, Scratch or CLI. I choose CLI then I'll change it to Desktop.
  4. (Optional) Inside Internationalisation Options change the local to en_US.UTF-8 UTF-8 and unselect en_GB.UTF-8 UTF-8
  5. (Optional) Inside Internationalisation Options change the Timezone
  6. (Optional) Enable Camera if you have a one like this one.
  7. Enable SSH inside Advanced Options.
  8. Finish and Reboot. When the Raspberry Pi boot you'll see the login prompt or the Desktop (as you choose in step #3). The user is pi and the password is raspberry if you didn't change it.
  9. Once you are back into the console upgrade the system with
  10. sudo apt-get update
    sudo apt-get -y upgrade
    
  11. Install any package you need. For example vim and chromium
  12. sudo apt-get install -y vim chromium
    
  13. Finally, restart the Raspberry Pi
  14. sudo shutdown -r now



VNC Access

If you enable SSH with raspi-config (step #7 in configuration subsection) you can ssh to the server if you are in the same network. Log in locally to the server to identify the IP address:
ifconfig eth0
From your Mac open the Terminal and type: ssh pi@IP_ADDRESS, in my case is:
ssh pi@192.168.10.100

Install and setup the VNC Server
sudo apt-get install -y tightvncserver
Start the X server (Desktop) and check it is running correctly. This command will prompt you to enter a Password and an optional View Only Password (I choose not to set a View Only Password)
startx &
tightvncserver
You will see a line with something like this: raspberrypi:1
In your Mac open Finder and press Ctrl+K or go to the menu: Go -> Connect to Server. In the new windows enter:
vnc://192.168.10.100:5901
Notice the last 2 digits are for the port you get when you started the VNC server, in this case it was 1 (raspberrypi:1) so you need to connect to the VNC server in port 5901 (vnc://192.168.10.100:5901)

Create the VNC service
You do not want to login through SSH, start the X Server and the VNC server every time you need to access the Graphic Interface. So, it is time to create a service that will start the X Server and the VNC Server when the server boot.

Type the raspi-config command:
sudo raspi-config
Go to Enable Boot to Desktop/Scratch and select the second option Desktop Log in as user pi at the graphical desktop. Go to Finish and then Reboot.
Login again to the server through SSH or open the Terminal in the Desktop. Create a new file named /etc/init.d/vncserver:
sudo vim /etc/init.d/vncserver
(If you do not have vim yet, install it with: sudo apt-get install -y vim )
To type this:
#!/bin/sh
### BEGIN INIT INFO
# Provides: vncserver
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start VNC Server at boot time
# Description: Start VNC Server at boot time.
### END INIT INFO

USER=pi
HOME=/home/pi

export USER HOME


case "$1" in
 start)
  echo "Starting VNC Server"
  su $USER -c "/usr/bin/vncserver :1 -geometry 1920x1080 -depth 24 -dpi 96"
  ;;

 stop)
  echo "Stopping VNC Server"
  su $USER -c "/usr/bin/vncserver -kill :1"
  ;;

 *)
  echo "Usage: $0 {start|stop}"
  exit 1
  ;;
esac

exit 0
And execute the following commands to add it as a service:
sudo chmod 755 /etc/init.d/vncserver
sudo update-rc.d vncserver defaults
Reboot and now, as you did before, connect from your Mac to the Raspberry Pi server using VNC protocol. Open Finder and press Ctrl+K or go to the menu: Go -> Connect to Server. In the new window enter:
vnc://192.168.10.100:5901
Do not save the URL yet, you'll do it in the next session.




Setup WiFi


We have access to the Raspberry Pi and it have access to Internet through a network cable but lets get rid off that cable and setup the WiFi. Get the Wi-Fi Dongle (I have an Edimax EW-7811Un), hook it up to the USB port and start up the Raspberry Pi. We'll continue with the network cable in the Raspberry Pi during this process, then you can unplug it and never use it again. There are 2 ways to setup WiFi: Using the GUI or the Command Line.

Setup WiFi using the GUI
Using the GUI to setup WiFi is easier and (in my case) works at first time. For this you need access to the Raspberry Desktop remotely with VNC (see below how to setup VNC access).

You can do it also locally but if so you will need a mouse and we do not have more USB port for a mouse, so you need a USB Hub or a Logitech Wireless Combo (Mouse and Keybpard) with a Unifying USB receiver. If this is your case then start the X server with:
startx

Open WiFi Config application, it is located in the Desktop. Click on the Scan button and double click in the network you want to connect to. A new window will appear, keep the defaults unless you are sure something is wrong. Enter the password in the PSK field and click on the Add button.

The WiFi network should be ready, to confirm and know the IP address enter this command:
ifconfig wlan0
If there is an IP address, copy it and now you can remove the network cable and restart the Raspberry Pi.

Setup WiFi using the GUI without a mouse
In case you are logged in the Raspberry Pi locally and do not have a mouse it is possible to do it but is not as simple as explained below. Start up the X server as before with the startx command.
Open the WiFi Config program by pressing Cmd+r (Cmd is the key with the Windows icon), in the new opened window type: wpa_gui
In the WPA GUI application you can use the tab, space, enter and arrows keys to move around.
NOTE: I could not find a way to do a double click with the keyboard. If you know how, please, let me know.
Go to the tab "Managed Networks", then go to the "Add" button and press space. In the new window enter the name of the SSID (previously you can go to Scan, press Esc to exit this screen without saving), the Authentication method, encryption and PSK (password). Go to the "Add" button and press space.

To exit press Cmd+r again and type sudo shutdown -r now to reboot the Raspberry Pi. When it boot the WiFi network should be working, if not, try to find a way to simulate a mouse double click with the keyboard and follow steps in previous sub-session.


Setup WiFi using the Command Line
This way is a more difficult than the GUI way but it may be needed in case there is no VNC or X Server available.

Once you are in logge in (remotely with SSH or locally), save a copy of the file /etc/network/interfaces and open it with nano, vi or vim
sudo cp /etc/network/interfaces /etc/network/interfaces.org
sudo vim /etc/network/interfaces
to have these lines in the file:
auto lo

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
If at the end of the process the WiFi is not working, replace the highlighted manual to dhcp, and the roam to conf.
Check the available WiFi networks and copy the SSID you want to connect:
iwlist wlan0 scan | grep SSID
Save a copy and open the file /etc/wpa_supplicant/wpa_supplicant.conf with nano, vi or vim:
sudo cp /etc/wpa_supplicant/wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant.conf.org
sudo vim /etc/wpa_supplicant/wpa_supplicant.conf
to add these lines:
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
  ssid="THE_SSID_TO_CONNECT_TO"
  psk="THE_SSID_PASSWORD"
  proto=RSN
  key_mgmt=WPA-PSK
  pairwise=CCMP
  auth_alg=OPEN
}
I'm not sure if it is important, but the lines inside the network block start with a tab character. Depending of your WiFi network configuration you may need to change some values such as proto (could be RSN or WPA), key_mgmt (could be WPA-PSK or WPA-EAP) and pairwise (could be CCMP or TKIP). You can identify these values with the command:
iwlist wlan0 scan
Restart the network service and force to get a new IP if you are log in locally or shutdown the Raspberry Pi if you are log in remotely with SSH:
sudo /etc/init.d/networking stop
sudo /etc/init.d/networking start
sudo dhclient

sudo shutdown -r now
Check you have an IP address for wlan0:
ifconfig wlan0
Copy the IP address, you will need it later.

Setup WiFi using the wpa_cli command
Other way, instead of modifying files, is to execute the wpa_cli command but I have not tested enough this way. The commands to execute in wpa_cli are:
Selected interface 'wlan0'

Interactive mode

> scan
OK
<3>CTRL-EVENT-SCAN-RESULTS 
> scan_results
bssid / frequency / signal level / flags / ssid
07:b1:23:a6:83:55   2412    62  [WPA2-PSK-CCMP][WPS][ESS]   MY_NETWORK_SSID
> add_network
1
> set_network 1 ssid "MY_NETWORK_SSID"
OK
> set_network 1 psk "MY_NETWORK_PASSWORD"
OK
>
The next output should be the client trying to connect. Once connected will try to get an IP address, if not working then force it to get one with:
sudo dhclient
Again, check you have an IP address for wlan0:
ifconfig wlan0




SSH Access


Static IP Address
The IP is assigned by DHCP and eventually the IP could be different. So, it is better to assign an static IP address.
Open the file /etc/network/interfaces again
sudo vim /etc/network/interfaces
to change this line iface wlan0 inet manual into iface wlan0 inet static. If in case of manual you have dhcp, replace it to static too.
In the line having wpa_roam, replace it to wpa_conf. And add these lines below the line iface wlan0 inet static:
address IP_ADDRESS
netmask 255.255.255.0 
gateway ROUTER_IP_ADDRESS
Identify the router IP address with:
netstat -r -n
The second column named Gateway will tell us the gateway ROUTER_IP_ADDRESS.
And identify the current IP address with the command:
ifconfig wlan0
This will give you the value of IP_ADDRESS which is IP the DHCP server assign to the Raspberry Pi, you can use that (recommended) or you can use other in the same network.
In my case, the file /etc/network/interfaces have the values:
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.254
Summarizing, the file /etc/network/interfaces should look like:
auto lo

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.254
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp

Using hostname instead of IP
The hostname of the Raspberry Pi is raspberrypi but you can confirm that with the command:
hostname
Instead of use the IP address of the Raspberry Pi every time we want to connect to it lets use the hostname. Open in your mac the file /etc/hosts and add this line to the end:
192.168.1.100    raspberrypi
The first value is the Static IP address of the Raspberry Pi and the second value is the hostname of the Raspberry Pi. Both values are separated by a tabulator character (press tab key).

Get rid of the password
Now lets setup the ssh access to not enter the password every time we connect with ssh from our Mac. Generate a private and public key if you don't have any. If you have the files ~/.ssh/id_rsa and ~/.ssh/id_rsa.pub, then you have them. If not generate them with the command:
ssh-keygen
Press enter when ask for a passphrase (no passphrase)
In the Raspberry Pi create the .ssh directory in the home of pi:
mkdir ~/.ssh
chmod 700 ~/.ssh
Now send the public key of your Mac to the Raspberry Pi executing this in the Terminal of your Mac:
cat ~/.ssh/id_rsa.pub | ssh pi@raspberrypi 'cat >> ~/.ssh/authorized_keys'
Change the pi password
This step is optional, you can do it if you want nobody enter to your Raspberry Pi. Also, besides sharing SSH, you can share the Screen and Folders.
To change the pi password type:
passwd
You need to enter the current password (raspberry) then the new one, twice. In case the password is not accepted (too weak) you can force it with:
sudo passwd pi
But, this is not recommended, the goal of this is to have a strong password.

Creating shortcuts
Lets get more lazy and create a function named rpi to do some commands like ssh to the Raspberry Pi, ping the Raspberry Pi to know if it is alive or not, and others we may want.
Open the .bashrc file in your home directory of your Mac:
rpi() {
  [[ "${1}" == "ssh" ]] && ssh pi@raspberrypi
  [[ "${1}" == "ping" ]] && ping raspberrypi
  [[ "${1}" == "hostname" ]] && echo "raspberrypi"
  [[ "${1}" == "ip" ]] && ping -q -c 1 -t 1 raspberrypi | grep PING | sed 's/.*(\(.*\)).*/\1/'
}
Close the file and reload it
. .bashrc
or close and open your session. Now if you type:
rpi ssh
You will login to the Raspberry Pi without enter the password.
Or, typing:
rpi ping
Will ping the Raspberry Pi to know if it is alive.
Create as many options as you want inside the rpi function.

More alias, in the Raspberry Pi
Log in to the Raspberry Pi and open the file ~/.bashrc. There are some alias that are comment out. Feel free to uncomment or add new alias or functions. In my case I uncomment:
#alias ll='ls -l'
#alias la='ls -A'
#alias l='ls -CF'
Close the file and reload the .bashrc file or close and open the SSH session.

Save VNC URL
In the VNC Session section you had to open a VNC session with Ctrl+K and enter the VNC URL. Now use this URL:
vnc://raspberrypi:5901
And save it pressing the button with the plus next to the URL. Next time you don't have to type it.

Improve performance by eliminating one X session
When you start the Raspberry Pi in the monitor will start a X session (you will see the Desktop), with number 0, and with the VNC server there is other X session with number 1.
Unless you need to work with the first X session, number 0, you can disable this one. So, when you start your Raspberry Pi what you will see in the monitor will be the prompt requesting the user to log in. And, if you need eventually the Desktop in the monitor, you can always start it with the command: startx
To disable the first X session type the raspi-config command:
sudo raspi-config
Go to Enable Boot to Desktop/Scratch and select the first option Console Text console, requiring login (default). Go to Finish and then Reboot.
When the Raspberry Pi boot, you won't see the Desktop, just the login request, but you can continue using the Graphic Interface with VNC and later (continue reading) with Share Screen of Mac.



Sharing Files and Share Screen to a Mac with AFP

We have VNC but if we are using a Mac it is better to use AFP because is built-in in OSX. Lets start by installing nettalk:
sudo apt-get install -y netatalk
When it finish you should see raspberrypi in the Finder side bar but it allows you only to share files in the pi home directory.
Now lets install the open source version of Bonjour with:
sudo apt-get install -y avahi-daemon
sudo update-rc.d avahi-daemon defaults
sudo vim /etc/avahi/services/afpd.service
The last command is to open the file /etc/avahi/services/afpd.service and then copy-paste this:
<?xml version="1.0" standalone='no'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
  <name replace-wildcards="yes">%h</name>
  <service>
    <type>_rfb._tcp</type>
    <port>5901</port>
  </service>
</service-group>
Now restart the service:
sudo /etc/init.d/avahi-daemon restart
Again, you should see in the Finder side bar the Raspberry Pi and in the right side the option to Connect and Share Screen.
Now you can use your favorite text editor (Sublime Text, Text Mate, ...) in your Mac to edit files in the Raspberry Pi. And, you can open the Raspberry Pi screen easily to open graphical programs.

Sharing other directories
By default just the pi home directory will be shared (or the home of the user you use connect to the Raspberry Pi). In case you want to add other directory open the file /etc/netatalk/AppleVolumes.default
sudo vim /etc/netatalk/AppleVolumes.default
Go to the end of the file and add as many directories you want after the line to share the "Home Directory":
# By default all users have access to their home directories.
~/                      "Home Directory"
/var/www                "WWW"
# End of File

Restart the avahi-daemon and in Finder, connect and disconnect form the raspberrypi.
sudo /etc/init.d/avahi-daemon restart
In this example I'm sharing /var/www because I installed Apache2:
sudo apt-get install -y apache2
Modify the index.html file and view it from your Mac with:
http://raspberrypi
In case you want to share only files and not the screen, replace these 2 lines of the file /etc/avahi/services/afpd.service:
<type>_rfb._tcp</type>
<port>5901</port>
To these lines:
<type>_afpovertcp._tcp</type>
<port>548</port>
You can also save the AFP URL to connect to the shared home directory of user pi. In Finder press Ctrl+K and in the windows type:
apf://raspberrypi
Now save the URL pressing the button with the plus sign. Next time you won't have to type the URL.



Sharing Files with Samba

Why share with Samba if I'm already sharing with AFP?
AFP is just for OSX, if you want to share a folder in your network for any computer (Windows or Linux) then Samba is the solution. You can hook up an external hard drive and use it as a NAS.
First, install samba and create a Samba user:
sudo apt-get install -y samba samba-common-bin
sudo smbpasswd -a pi
Now open the smb.conf file
sudo apt-get install -y apache2
to change:
  • (Optional) Windows Workgroup:
  • Change the WORKGROUP to the Windows Workgroup you have in your network. Check it in your Windows computer.
    workgroup = WORKGROUP
    
  • Enable Authentication:
  • Find this line and remove the #.
    #   security = user
    
  • Share a directory:
  • Go to the end of the file to the Share Definitions to add these lines
    [NAME]
       path = /path/to/the/share/folder
       comment = Comment about this folder
       valid users = pi
       writeable = yes
       browseable = yes
       create mask = 0777
       public = yes
    
    Replace NAME to the name to be displayed from other computers, /path/to/the/share/folder to the path of the directory to share, and Comment about this folder to a description about this share directory. The other settings may change according to what you want to share. In case this is a NAS, NAME could be NAS, the path is /media/NAS and the comment could be: Raspberry Pi NAS
    Finally, restart Samba:
    sudo /etc/init.d/samba restart
    
    and you can connect to the Raspberry Pi with Samba, just open Finder, press Ctrl+K and enter the URL:
    smb://raspberrypi/NAS
    Here


    Access form iPad or iPhone

    Now that you have access to the Raspberry Pi through SSH and VNC it is just a matter to have a SSH and/or VNC client for your iPad or iPhone. You can choose the one you prefer or can afford, in my case I use: vSSH (this is just for SSH) and Remote VNC (I think the free version is just for VNC, the paid version allow any kind of protocol, including SSH)
    Depending of your application, add the server entering the server name, IP address (do not use raspberrypi, this is a name just for your Mac), port (5901), user (pi) and password. Remember to have the iPad or iPhone in the same network as the Raspberry Pi.



    Sources

    Tuesday, May 6, 2014

    Database Cheat Sheet






    This is a summary of the SQL, MySQL and SQLite commands that I use the most. I use it as my own Database Cheat Sheet but could be useful for you too. Feel free to copy & paste!

    Open Database

    Assign values to the variables or replace them with the values in the command. In this case MySQL will ask for password.
    MySQLSQLite
    USER=
    DB=
    mysql -u $USER -p $DB
    
    DBFile=
    sqlite3 $DBFile
    

    Create User in MySQL

    Assign values to the variables or replace them with the values in the commands. MySQL will ask for the root password.

    In these examples I'm using 'localhost' to grant access from localhost only but if you want to grant remote access you can use the wildcard '%' to grant access from any server or specify the IP or Host name or a combination of both like in: '%.domain.com' or '127.0.0.%'

    USER=
    PASSWD=
    HOST=localhost
    mysql -u root -p   -t<<EOSQL
    CREATE USER '$USER'@'$HOST' IDENTIFIED BY '$PASSWD';
    GRANT ALL PRIVILEGES ON * . * TO '$USER'@'$HOST';
    FLUSH PRIVILEGES;
    EOSQL
    

    If required to restrict the access replace the permissions, database or table in this line:

    GRANT type_of_permission ON database_name.table_name TO ‘$USER’@'localhost’;
    

    Where:
    type_of_permission: could be ALL PRIVILEGES, CREATE, DROP, DELETE, INSERT, SELECT, UPDATE, GRANT OPTION. If you want to grant more than one permission, execute one SQL GRANT command per permission.
    database_name: is the database name in the table specified. Use * (asterisk) for any database.
    table_name: is the table to grant the permission where the table is. Use * (asterisk) for any table.

    Made a mistake? Revoke the permission or drop the user.

    REVOKE type_of_permission ON database_name.table_name FROM ‘$USER’@‘localhost’;
    
    DROP USER ‘$USER’@‘localhost’;
    

    After any change, remember to flush the changes with:

    FLUSH PRIVILEGES;
    

    Saturday, April 12, 2014

    Calculate Your Tip with Siri

    There are times, such as at the end of a long dinner with a large group of friends, when figuring out a tip requires more advanced math skills or sobriety than you currently have. In these situations, Siri can do the math for you.
    Need to figure out everyone's share of the tip? Ask Siri, "What's 18% of $74 divided by three people?"
    Need to figure our your share of half the cost of a shared dessert, plus two glasses of the house white, plus your entree, plus your share of the birthday person's meal, plus a tip? Siri can add it all up for you.