I'm not sure dynamic
is the right word in the title, But i can't find a more suitable word. I'll create a generic nginx vhost/config that'll serve all symfony project.
Create a new file in nginx config directory, Ex: /etc/nginx/conf.d/symfony.conf
Put the following config in it. Be sure to reload/restart nginx afterwards.
server {
listen 80;
server_name ~^(?<project_name>[^\.]*)\.(?<env>prod|dev)$;
set $app "app.php";
if ($env = "dev" ) {
set $app "app_dev.php";
}
root /Users/sarim/Sites/php55/$project_name/web;
index $app index.html index.htm;
location / {
try_files $uri $uri/ /$app?$args;
}
location ~ ^/(app|app_dev|config)\.php(/|$) {
fastcgi_pass unix:/usr/local/var/run/php55.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Put your php-fpm address in fastcgi_pass
. You'll also need to edit the /Users/sarim/Sites/php55
part. Thats where i put my php framework projects. Now lets assume you have a project named matrix
in that folder. Now go ahead and add following lines into /etc/hosts
127.0.0.1 matrix.dev matrix.prod
Now open http://matrix.dev/ and http://matrix.prod/ in your browser. You should see the matrix
project in dev and prod mode. Try any other project in that folder. It'll work :)
So whats happening here ? the magic is in the server_name line. A little bit of regex that matches anything but dot, goes into project_name
variable. And prod
or dev
after the dot, goes env
variable. After that we set app
variable to app.php
assuming our environment is prod. But if env == dev, it sets to app_dev.php
. This app
variable is used later to set which front controller we send user request to.
PS: You can further automate the process by installing a intelligent DNS server and configure it to send .*dev|prod
requests to 127.0.0.1
.
Happy Coding.
]]>Now i want to persist some changes, i installed some packages, created some files, i want to have them when i boot this live system again. Easy, just add some persistent space when creating the live usb. But if i want to do that in virtualbox ? What if i dont want to reboot my pc, i want do my other tasks and want to try out ubuntu in parallel ? Voila! install that ubuntu inside virtualbox. OK, but now i dont want to waste a few gigs of my disk space (not to mention the time to install ubuntu). I want to use persistance with that live system. There was no way till now :(
But fear not, Thats what i'm going to do now :D I'm gonna make a virtualbox image from ubuntu iso, adding a persistent space with it in the process.
I did this in mac, but pretty same process will be applicable for linux too (hopefully). Now head over to terminal and follow the steps.
Lets create a folder and do all the bullshitting inside it.
$ mkdir ubuntulive
$ cd ubuntulive
Lets make a empty 1.0GB image to hold all that bullshit.
$ dd if=/dev/zero of=ubuntu.img bs=1m count=1024
$ ls -lsh
total 2097152
2097152 -rw-r--r-- 1 sarim staff 1.0G Dec 18 02:42 ubuntu.img
Bullshit container creation done, now register this bullshit as disk in the system.
$ open -a Disk\ Utility ubuntu.img
In Disk Utility, right click on the ubuntu.img
in the left side pane. Select Open Disk Image
from popup menu. It'll show a error msg.
Now check the disk listing, you'll see a new disk added at the end. It is /dev/disk6
for me.
$ diskutil list
/dev/disk6
#: TYPE NAME SIZE IDENTIFIER
0: *1.1 GB disk6
Yay ! our bullshit disk is registered in the system :D
Now lets partition the disk. We are going to create a fat32
partition named UBUNTULIVE
.
$ diskutil partitionDisk /dev/disk6 1 MBRFormat fat32 UBUNTULIVE 100%
Started partitioning on disk6
Unmounting disk
Creating the partition map
Waiting for the disks to reappear
Formatting disk6s1 as MS-DOS (FAT32) with name UBUNTULIVE
512 bytes per physical sector
/dev/rdisk6s1: 2093024 sectors in 261628 FAT32 clusters (4096 bytes/cluster)
bps=512 spc=8 res=32 nft=2 mid=0xf8 spt=32 hds=128 hid=2 drv=0x80 bsec=2097150 bspf=2044 rdcl=2 infs=1 bkbs=6
Mounting disk
Finished partitioning on disk6
/dev/disk6
#: TYPE NAME SIZE IDENTIFIER
0: FDisk_partition_scheme *1.1 GB disk6
1: DOS_FAT_32 UBUNTULIVE 1.1 GB disk6s1
Now the UBUNTULIVE
drive will be mounted in finder. Open Unetbootin
. Select the iso, enter some how much space you want for persistance. Select /dev/disk6s1
in Drive
. Click OK and Let it finish making the live disk. It happens in a snap in my ssd powered system, your experience may vary.
After unetbootin is finished, Go to UBUNTULIVE
drive. Inside the drive, open syslinux.cfg
in a text editor. (I used Textmate). Add the following lines at the end.
label ubnentry6
menu label ^Try Ubuntu without installing in Gittu way
kernel /casper/vmlinuz
append initrd=/casper/initrd.lz live-media=/dev/sda1 live-media-path=/casper/ file=/cdrom/preseed/ubuntu.seed ignore_uuid boot=casper quiet splash -- persistent
Save the file and unmount/eject the UBUNTULIVE
drive.
GUI time is over, back to terminal. Now our image is ready. Convert it for virtualbox.
$ VBoxManage convertfromraw -format VDI ubuntu.img ubuntu_vbox.vdi
Converting from raw image file="ubuntu.img" to file="ubuntu_vbox.vdi"...
Creating dynamic image with size 1073741824 bytes (1024MB)...
Phew! Done :D Now open virtualbox. Create a new vm/Edit Existing, in storage section, select Choose Existing Disk
and select this ubuntu_vbox.vdi
there. Boot the vm, in unetbootin menu, select the last option and press enter to boot.
$ gparted ./ubuntu.img
will do.live-media
is needed for 13.10. That was taken from schmidi2.wordpress.com. If you are using another version, you may ommit the flag in step 8.count
param) in step 2 too. Now, this thing still wasted 2gigs of disk space, didn't it ? So whats the point ? There is none :v you may take it as bullshitting, or a scienctific experiment for educational purposes, your wish. Good luck and Happy linuxing (y)
]]>Unfortunately sqlite doesn't have any native repair feature, unlike mysql. So fixing a sqlite3 means dump it and then create a new db from that dump file. Lets see how to do that with chrome's profile databases.
Close chrome and follow the instructions below in terminal.
First we need to get a list of all sqlite3 database in chrome's profile folder.
find ~/Library/Application\ Support/Google/Chrome/ -print0 | xargs -0 file | grep SQLite | sed 's/\(.*\):.*/\1/' > ~/chromedb.txt
Replace ~/Library/Application\ Support/Google/Chrome
with your chrome profile path.
Here i'm piping 4 commands, firstly i'm using find
to get all files from chrome profile, secondly using xargs
i'm checking file type of these files using file
command, thirdly filtering the SQLite databases using grep
, at-last using sed
to extract the file path part from the output. Then saving it in ~/chromedb.txt
Download the repairsqlite.sh script.
curl -o repairsqlite.sh https://gist.github.com/sarim/6460936/raw/repairsqlite.sh
or
wget https://gist.github.com/sarim/6460936/raw/repairsqlite.sh
Make it executable
chmod +x repairsqlite.sh
Now run this script with our chromedb.txt
cat chromedb.txt | xargs -I db ~/repairsqlite.sh db
You'll see tons of text flowing through your terminal. Wait a few seconds until its done.
Now open chrome and "Profile Corrupt" message will be gone and your profile will be saved again.
Happy browsing with Chrome :)
]]>Check my site's footer. You'll see a site version ####
. What is it ? Its just a fancy jekyll plugin i created that shows a version based on git commit. Everytime you add a new commit to your site source, the version increases.
Q: Why need it ?
A: It looks cool. It gives me internal peace of mind. Moreover If you publish your site in places like github pages, from version you can check if your site is deployed yet.
plugins
folder.Now open any layout and add {% get_version %}
in it. Example: I added it in my _includes/custom/footer.html
<span class="credit">site version {% get_version %}</span>
Since it works based on git, you need a git tag to generate a version number. If you dont have any git-tag yet, create a new tag. Note that tag name will be used as prefix in the version. To create a tag named MySite
git tag -a MySite
Now regenerate your site using rake generate
and you are done.
Let me know how much you like this plugin :)
]]>Now twitter provides a widget with limited customizing functionality to embed one's tweets. But you can't use your own design with that, you are stuck with two "light" and "dark" theme twitter is so kind to provide.
Today i came up with a hack around this widget, you still need to create a widget from twitter, but you can create your own widget with it. How ?
Check the DEMO first.
Now check the sources, things are pretty self-explanatory. The twitter widget creates a iframe. Interesting thing is, instead of just loading the iframe from twitter, it creates a empty iframe, then writes the html inside the iframe. The src attr of iframe remains empty, that enables us to access it freely. Thats what i did, i let it load, made it invisible by sending it off the page using css. Now i just parsed the tweets from the iframe and created my own widget.
You can also see it in my site's sidebar.
Let me know your ideas about this in the comments section below.
]]>Let's make zypper download packages in the speed of light using aria2 :D
First install aria2. You can install it from repo, sudo zypper in aria2
or from software.opensuse.org
Now we need to tell zypper (libzypp to be technically correct) to use aria2, passing ENV Variable ZYPP_ARIA2C
is needed for this. Open /etc/bash.bashrc
for editing.
1
sudo nano -w /etc/bash.bashrc
Keep pressing Cntrl + v
for scrolling down. At the end of the file, add this line.
1
export ZYPP_ARIA2C=1
Cntrl + X
, Y
, Enter
)
Now Zypper will use aria2 for downloading as root user, but when using sudo, that ENV variable will be striped. To fix this, edit /etc/sudoers
1
sudo nano -w /etc/sudoers
1
Defaults env_keep = "LANG LC_ADDRESS LC_CTYPE LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE LC_TIME LC_ALL LANGUAGE LINGUAS XDG_SESSION_COOKIE"
ZYPP_ARIA2C
at the end of this line.
1
Defaults env_keep = "LANG LC_ADDRESS LC_CTYPE LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE LC_TIME LC_ALL LANGUAGE LINGUAS XDG_SESSION_COOKIE ZYPP_ARIA2C"
Save and Exit.
Done. Restart terminal and try to download a package using zypper. Zypper will now use aria2. I noticed a bug though, you wont be seeing the download progress, but i can live with it, dont u ? :)
This guide is written in openSUSE 12.3 KDE, but the process will be similiar for other versions of openSUSE.
Happy Linuxing :D
]]>??????
, and fix: go and change collation to utf8 :D
But my problem started from this simple (yes it looked simple :S ) problem but ended up a nightmare.
I was running a ipboard instance. When importing a bangla translation, the text was showing as ??????
, so i applied the common fix, changed all table and field collation to utf8_unicode_ci and ipb's encoding to utf8. Now the site became inaccessible, showing a preety "Fatal ERROR : Your settings could not be read by IP.Board". That was fixed by running ipb's upgradeFinish
script but the real problem starts now.
All bangla letters became this :
Looks pretty right ? :v
The reason behind this was all bangla chars were inserted in mysql using latin1
encoding. If I set mysql client's encoding to latin1 and read, i get real bangla. If I set encoding to utf8 and read, i get latin-fied bangla like the picture.
I immediately went on a long google search and tried several solutions, but unfortunately, none of them were able to solve the problem completely. These two links (1 2) were a great help though, which helped to understand the problem thoroughly.
The solution proposed in first link, was a partial success. Change the fields in squence of utf8 > latin1 > blob > utf8. The trick in converting to blob is it fools mysql to convert latin1 to utf8 without running any conversion algorithm. It works when checking a single field, but not for all, the whole database of ipb is kinda complex. Some field were primary field and mysql not allows them to altered to blob. I ran a script to loop through all table,all field and alter them but ended up with a bunch of error and corrupted database.
Then i changed my focus to the mysql dump file. If i can change the latin text inside the sql file to unicode text, problem will be gone. I tried enca(1) but it failed to change anything. Tried recode(1) without any success.
Then i created a script in php to read the whole sql line by line and feed them through utf8_encode. Which made the unreadable latin text to unreadable capital letter latin.
That was a mistake, actually i need to use utf8_decode. So now, the texts were back to bangla, but also many(almost all) chars are missing. Only first letter of a word or one word of a sentence was there, the rest vanished into the wind.
Next, tried iconv(1) which striped away half of the database :(
The idea is to insert the db to mysql as latin1, dump the db as latin1. Edit the dump to change it to utf8 and insert it as utf8.
1 2 |
|
Now i inserted this database.sql into mysql. Now we need to extract it as latin1, so applying --default-character-set=latin1
flag.
1
mysqldump --default-character-set=latin1 -u user -p dbname > database_latin.sql
Now we need to edit the dump file and change it to utf8, as we are gonna insert it as utf8 now. again, sed to rescue.
1
2
3
4
sed -i 's/SET NAMES latin1/SET NAMES utf8/g' database_latin.sql
sed -i 's/CHARSET=latin1/CHARSET=utf8 COLLATE=utf8_unicode_ci/g' database_latin.sql
sed -i 's/COLLATE latin1_bin/COLLATE utf8_unicode_ci/g' database_latin.sql
sed -i 's/CHARACTER SET latin1/CHARACTER SET utf8/g' database_latin.sql
Finally i inserted this database_latin.sql to mysql and voila :D no error, clear bangla and no chars missing :D
If you are making a bangla or non-english site, always start with a proper collation setting. Set all table and field collation to utf8_unicode_ci or utf8_general_ci. Make sure the mysql client (your app) speaks in utf8. If you are running raw mysql query, run set names utf8
at beginning. If using a framework or toolkit, check where to set this utf8 config. These will save you from infinite PITA later.
If you indeed missed the utf8 config and ended up in a mess like me, try to apply a solution that doesn't directy convert the encoding of the texts. You may end up with missing or corrupted chars.
NB: If you are following this post, dont copy-paste the commands, understand and adept the commands to your scenario. Forgive my poor writing and let me know your thoughts in the comment section.
]]>Lets say you have some users talking in a mumble server and want to brodcast that conversation but dont want people to join and interfare but want people able to listen to. So, here's how to do that.
Here i'm gonna do it in ubuntu.
1
|
|
If you are doing this in a headless server you'll also need vncserver. Realvnc is my favorite but tightvnc will also do.
1
apt-get tightvncserver
Now install icecast
1
apt-get install icecast2
if you choose not to configure icecast2 during installation here's how to do that manually.
Open /etc/icecast2/icecast.xml
1
|
|
There is many configuration with comments, change them if you want, but at least we need to change the default passwords. change <source-password>
, <relay-password>
and <admin-password>
Now enable icecast2, open /etc/default/icecast2
1
nano /etc/default/icecast2
1
ENABLE=true
Now start icecast2
1
/etc/init.d/icecast2 start
Point your browser to SERVER_IP:PORT to see icecast.
Skip this if you already have installed and access to Desktop Environment.
Now to run mumble, we need a DE. you may install lxde (as a lightweight DE)
1
apt-get install lxde
Start a vnc session which will also start the X server.
1
vncserver
Now go to your own computer's desktop and using any VNC client, connect to you server. Credentials will be like host: serverip:1
and your vnc password.
Assuming you were using ssh so far, now switch to DE, and start lxterminal to further complete tasks ahead.
Now we need to create a virtual device in pulseaudio from where we'll be capturing the mumble session and to where mumble should send its output.
To do that, run,
1
pactl load-module module-null-sink sink_name=stream
Start mumble from menu or running mumble
in terminal. Most important thing to set is
System = PulseAudio
Device = Null Output
You can leave other configs as default.
Now connect to desired mumble server/channel.
Now the final task, link mumble's output to icecast. It is a good idea to check out quick start guide which'll give you a clear idea about Liquidsoap.
We'll create a liq script.
1
nano sk.liq
Now the main tricky part, you need to change the content of the script.
1 2 |
|
You need to change example_host
to your icecast server's ip or address. source_password
to the <source-password>
set in icecast.
Now everything is set, fire things up :)
1 2 |
|
Now go to icecast and listen your mumble conversation :)
liquidsoap -v sk.liq
if you are having trouble with it.Thats all :D Let me know your thoughts in comment section.
]]>No Worry, i asked uncle G and now writing down the procedure in case i forgot it in future :P
The smilify plugin is here jekyll_smilify
git clone git://github.com/SaswatPadhi/jekyll_smilify.git
Assuming we cloned octopress to ~/octopress
and jekyll_smilify to ~/jekyll_smilify
cd jekyll_smilify/
cp plugins/smilify.rb ~/octopress/plugins/
cp -r source/images/smileys ~/octopress/source/images/
cp -r source/_include/smileys/ ~/octopress/source/_includes/smileys/
Placing things in write place is done. Now need to enable the contents to filter through Smilify.
Open ~/octopress/source/_layouts/default.html
and replace
{{ content | expand_urls: root_url }}
with
{{ content | expand_urls: root_url | smilify }}
Then, open ~/octopress/source/_layouts/page.html
and replace
{{ content }}
with
{{ content | smilify }}
I see the css of the octopress theme was making the smiles to have a border around it and drop-shadow applied, which looks ugly. To fix this,
Open ~/octopresssass/custom/_styles.scss
and add
img.smiley { border : none ; box-shadow: 0 0 0 0 }
All Done :D
NB: We need to active the plugin again after installing a new theme.
]]>For a virtual_vagabond type people like me, who can't organize anything :P i think it is a daunting challenge to regularly maintain a blog.
Actually Octopress is what that encouraged me to open a blog, for a command line freak, it is just <3 <3 , create, manage, write new posts :D all from sweet terminal, who need anything else ?
I'll be using the great markdown editor Mou and iTerm2 for this.
sys.exit(0)