Function Declarations vs. Function Expressions

JavaScript, JavaScript...

Lets start with a short quiz. What is alerted in each case?:

Question 1:

Question 2:

Question 3:

Question 4:

If you didnโ€™t answer 8, 3, 3 and [Type Error: bar is not a function] respectively, read onโ€ฆ (actually read on anyway ๐Ÿ˜‰ )

View original post 1,220 more words

Posted in Uncategorized | Leave a comment

Backup raspberry pi sd card

Assuming you have an usb drive mounted on /home/pi/mnt/home/ you can create a bzip2 archive of the sd card with :

sudo dd if=/dev/mmcblk0 | bzip2 > /home/pi/mnt/home/sdimage.bz2

This will take a lot of time.
Later, you can restore the image to the SDcard with the following (didn’t test this command myself, proceed at your own peril ! )

sudo bzip2 -dc /home/pi/mnt/home/sdimage.bz2 | dd of=/dev/mmcblk0
-d means decompress
-c means output to standard output
Posted in Uncategorized | Leave a comment

Installing linux-dash on nginx on raspberry pi

Secondary title: How to monitor raspberry pi remotely

linux-dash is a cool project that displays stats about a linux machine through the browser. It is a cool webapp to install on the pi.

ldash

 

Credit goes to xmodulo. My post is very similar with a small path change for the pi.

First update the repository:

sudo apt-get update

Then install git (to pull the linux-dash code), nginx (the webserver) and php packages

sudo apt-get install git nginx php5-json php5-fpm php5-curl

Edit the linuxdash config

sudo nano /etc/nginx/conf.d/linuxdash.conf

On this file you want to paste the followin settings. Notice how the path for the site root is changed from the original how to. This is because this path is changed on the default raspbian configuration:

server {
    server_name     $domain_name;
    listen          8080;
    root            /usr/share/nginx/www;
    index           index.html index.php;
    access_log      /var/log/nginx/access.log;
    error_log       /var/log/nginx/error.log;

    location ~* \.(?:xml|ogg|mp3|mp4|ogv|svg|svgz|eot|otf|woff|ttf|css|js|jpg|jpeg|gif|png|ico)$ {
            try_files $uri =404;
            expires max;
            access_log off;
            add_header Pragma public;
            add_header Cache-Control "public, must-revalidate, proxy-revalidate";
    }

    location /linux-dash {
        index index.html index.php;
    }

    # PHP-FPM via sockets
    location ~ \.php(/|$) {
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_split_path_info ^(.+?\.php)(/.*)$;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            if (!-f $document_root$fastcgi_script_name) {
                    return 404;
            }
            try_files $uri $uri/ /index.php?$args;
            include fastcgi_params;
    }
}

Disable the default site configuration

sudo rm /etc/nginx/sites-enabled/default

Configure php-fpm to use the correct user www-data

sudo nano /etc/php5/fpm/pool.d/www.conf

and change the lines for the user and the group.

. . .
user = www-data
group = www-data
. . .

Pull linux dash code, install it on the correct folder and set permissions:

cd ~
mkdir temp
cd temp
git clone https://github.com/afaqurk/linux-dash.git
sudo cp -r linux-dash/ /usr/share/nginx/www/dash/
sudo chown -R www-data:www-data /usr/share/nginx/www/dash
sudo chown -R www-data:www-data /usr/share/nginx/www

Restart the services:

sudo service php5-fpm restart
sudo service nginx restart

Now you can monitor your pi via the url:

http://you-ip-address-here:8080/dash/
Posted in Uncategorized | Tagged , , | 6 Comments

Extract Audio from youtube video

Use the youtube-dl script to download video
http://rg3.github.io/youtube-dl/download.html

Use ffmpeg to convert to mp3 (variable bitrate)
ffmpeg -i input.mp4 -q:a 0 -map a output.mp3

Posted in Uncategorized | Tagged , , | Leave a comment

Start new Symfony2 project guide

Edit file Symfony/app/config/parameters.yml to point to database
Create db and schema:
php app/console doctrine:database:create
php app/console doctrine:schema:create

… To be continued ..

Posted in Uncategorized | Tagged , | Leave a comment

Raspberry Pi internet radio player – part 2

Had an unused cd player with lots of empty space inside. Perfect to hide the pi and keep it near the stereo.
Removed the back panel:
IMAG0385
Opened a hole to pass the cables. Metal working is not my strongest skill ๐Ÿ˜›
download
IMAG0388
Glued a pair of M2.5 screws with 4 bolts to raise the pcb.
IMAG0390

IMAG0391
IMAG0393

Posted in Uncategorized | Tagged , | Leave a comment

Raspberry pi internet radio player

Got myself a raspberry pi to serve as (among others) a webradio player. A few notes on how to do this.
1 – get the latest raspbian image from the official site

2 – burn the image on an sd card. There are instructions on how to do this on the site. I’ve used both ubuntu dd and windows win32diskImager.

3 – Connect the cables, power last and behold your first boot.
IMAG0380

4 (optional) – Find a nice case. I got the cheapest one I could find on the spot – a sardines box. lol
IMAG0383

5 – On the first boot menu, you should follow on screen instructions to configure the correct keyboard layout as well as enable sshd. This will allow you to connect remotely to the pi (without having the keyboard and screen/tv connected to it).

6 – Install audio stuff:
sudo apt-get install alsa-utils
sudo apt-get install mpg321
sudo apt-get install lame

7 – Change audio output to the 3.5mm jack (it can be either jack, hdmi or none). 1 is for the jack.
sudo amixer cset numid=3 1

8 – Test your sound. You should hear it in the speakers.
aplay /usr/share/sounds/alsa/Front_Center.wav

9 – Install mpd and mpc. Mpd is the music player deamon. A program that can play and/or stream music. The mpc is a client that knows how to talk to mpd and send it commands like play/stop/etc.
sudo apt-get install mpd mpc <- this first time I got an error on the urls
sudo apt-get update <- fix urls
sudo apt-get install mpd mpc <- try reinstalling

At this point mpd should be installed but I got a few errors that prevented me from starting it. Rebooted the pi and loaded ipv6.
sudo reboot
sudo modprobe ipv6
sudo /etc/init.d/mpd start <- start mpd

10 – MPD configuration, The configuration for mpd is in file /etc/mpd.conf there I changed the folder where I want mpd to “scan” for musics as well as allowing connections from any ip. This allows for MPDroid to work ๐Ÿ™‚
sudo nano /etc/mpd.conf <- edit file. Change the music_directory setting to the folder you want to store your music and bind_to_address set to "0.0.0.0" (instead of "localhost").
sudo /etc/init.d/mpd restart <- restart for config changes to take effect.

With this setup you can command your music player from your phone:
mpdroid

top
(Around 6-8% cpu playing mp3 file with mpd)

Next step on this project is finding a better case, a permanent power source (using the one from the cellphone) and a way to add online radios to mpd…

See ya

Posted in Uncategorized | Tagged , , , , , , | Leave a comment

Symfony2 Commands Reference

In these examples, the namespace is Company and the bundle is a ClassifiedsBundle (for a classifieds site).

To create a new Bundle:

php app/console generate:bundle --namespace=<namespace>/<project_name>/<something>Bundle --format=yml --structure=yes --no-interaction --dir=<fullpath_to_src_dir>

You can use as many sub-packages as you like (project_name) separated by /. They are optional.
e.g.

php app/console generate:bundle --namespace=Company/ClassifiedsBundle --format=yml --structure=yes --no-interaction --dir=c:\...\src

To generate an entity inside a bundle:

php app/console generate:doctrine:entity --no-interaction --format=annotation --with-repository --entity=CompanyClassifiedsBundle:Post --fields="title:string(255) body:text"

Generate a CRUD Controller from an entity:

php app/console generate:doctrine:crud --with-write --entity=CompanyClassifiedsBundle:Post --route-prefix=admin/post --no-interaction --format=yml

Then, because this uses the yml format, you need to paste the route code that is printed into your app/config/routing.yml

Posted in Uncategorized | Tagged , , | Leave a comment

Ubuntu scroll speed

Haha.. I knew it was too good to be true. There had to be something that wasn’t perfect.

Scroll speed in ubuntu is ridiculously slow (around 3 lines) and there is no way to control this. (!) From what I’ve read, you can change it on KDE, not on gnome. I’m giving gnome a go so.. my workaround involves changing settings in Firefox and Chrome

For browsers, there is a way to control scroll ๐Ÿ™‚ On FF, check this article:

http://www.pcworld.com/article/163639/Change_the_Speed_of_Mousewheel_Scrolling_in_Firefox.html

On Chrome, go to the extensions and install one called Chromium Wheel smooth scroll. (ย https://chrome.google.com/webstore/detail/chromium-wheel-smooth-scr/khpcanbeojalbkpgpmjpdkjnkfcgfkhb?hl=enย )

I changed the bounce setting to 0. But this gives me the scroll experience I’m used too. at least in the browser.

Posted in Uncategorized | Tagged , , , , , , | Leave a comment

wow.. Ubuntu doesn’t suck!

ubuntu-logo14

In the past I’ve tried many many times to switch to aย  linux distributtion as my main OS and always gave up.. always returning to Windows. It just wasn’t polished enough. I’ve seen all kinds of issues, from “critical errors” during installation to small nuissances (like audio not working, lack of hw acceleration, etc.). Also tried many distributions ..

Today I installed Ubuntu 12.10 on my 3yr old laptop and.. everything works!

Wireless, audio, video, screen resolutions, flash, EVERYTHING! EVERYTHING works flawlessly.

Besides.. it’s freakin’ beautiful. The font, the interface. It’s just .. wow.

Really happy to see the past issues fixed. Grats to everyone who works on this. Will definitely keep using it.

Posted in Uncategorized | Leave a comment