Apache Configuration - Hide hidden directories/files
Use the below snippet to hide hidden folders/files (matched by files or folders starting with a [dot] character.
RewriteRule (^\.|/\.) - [F]
Please make sure mod_rewrite is enabled in Apache.
occasionally subtle

Discoholic 🪩

oozey mess
todays bird
Show & Tell
One Nice Bug Per Day
Lint Roller? I Barely Know Her
Not today Justin
DEAR READER
No title available
noise dept.
No title available
Stranger Things
cherry valley forever

Origami Around
RMH
AnasAbdin
Cosimo Galluzzi
Misplaced Lens Cap
Aqua Utopia|海の底で記憶を紡ぐ

seen from India

seen from United Kingdom
seen from United States

seen from Singapore
seen from Italy

seen from United States
seen from United States

seen from Malaysia

seen from Bulgaria
seen from Finland

seen from Japan

seen from France
seen from United States

seen from Singapore

seen from Denmark

seen from Malaysia

seen from United Kingdom
seen from United States

seen from United States
seen from Italy
@shahalpk
Apache Configuration - Hide hidden directories/files
Use the below snippet to hide hidden folders/files (matched by files or folders starting with a [dot] character.
RewriteRule (^\.|/\.) - [F]
Please make sure mod_rewrite is enabled in Apache.
Command line utilities for disk space analysis in Ubuntu (or any Linux)
If you just need to find large files, you can use find with -size option. Below command will list all the files larger than 100MB.
find / -size +100M -ls
If you want to set an upper limit.
find / -size +100M -size -500M -ls
If you need a tool for better analysis, continue reading…
gt5
Years have passed and disks have become larger and larger, but even on this incredibly huge harddisk era, the space seems to disappear over time. This small and effective programs provides more convenient listing than the default du(1). It displays what has happened since last run and displays dir size and the total percentage. It is possible to navigate and ascend to directories by using cursor-keys with text based browser (links, elinks, lynx etc.)
ncdu
Ncdu is a ncurses-based du viewer. It provides a fast and easy-to-use interface through famous du utility. It allows to browse through the directories and show percentages of disk usage with ncurses library.
I personally prefer ncdu. It’s pretty fast and verbose than gt5. Go ahead and find for yourself.
Setup Odoo 10 to run as service
If you've followed my previous article on Odoo Setup, you would have an odoo setup running in your machine. Today i'll show you how to setup odoo to run as a service.
The following are the assumptions.
odoo sources are at the path /opt/code/odoo.
Local user odoo is part of the group odoo and owner and group of odoo sources folder is set to odoo.
Now follow the below steps to make odoo run as a service.
Move odoo binary into /usr/bin/odoo.
sudo cp /opt/code/odoo/odoo-bin /usr/bin/odoo
Create directory for saving odoo configuration
sudo mkdir /etc/odoo && sudo chown -R odoo:odoo /etc/odoo
Create directory for odoo logs.
sudo mkdir /var/log/odoo && sudo chown -R odoo:odoo /var/log/odoo
Create odoo configuration file.
odoo --save --config odoo.conf --stop-after-init mv odoo.conf /etc/odoo/odoo.conf
If you need to update any configuration, please do the necessary changes in /etc/odoo/odoo.conf file. Refer odoo reference for more information.
Create odoo service.
sudo cp /opt/code/odoo/debian/init /etc/init.d/odoo sudo chmod +x /etc/init.d/odoo sudo update-rc.d -f odoo start 20 2 3 4 5 .
Start odoo server.
sudo service odoo start
Now you can use ubuntu services to start/stop odoo server. If you face any difficutly mention me on twitter @shahalpk.
Installing Odoo 10 on Ubuntu 16.04 (Trusty)
To install odoo from source, follow the below steps.
Install the dependencies.
sudo apt-get install git python2.7 postgresql nano python-virtualenv
Install build dependencies
sudo apt-get install gcc python2.7-dev libxml2-dev libxslt1-dev libevent-dev libsasl2-dev libldap2-dev libpq-dev libpng12-dev libjpeg-dev node-less
Create new user odoo and set login password
sudo useradd -m -g sudo -s /bin/bash odoo sudo passwd odoo
Switch to user odoo
su odoo
Create Postgres user odoo. Allow user to create databases.
sudo -u postgres createuser --createdb odoo
Create new database odoo
createdb odoo
Create new directory for Odoo source code. Since i'm using a vagrant instance, i'll set it up inside /vagrant folder. If you're not using vagrant, u can setup the sources in your home directory.
mkdir /vagrant/odoo-dev # For vagrant users mkdir ~/odoo-dev # For non vagrant users.
Clone the odoo code base
git clone https://github.com/odoo/odoo.git -b 10.0 --depth=1
Setup python virtual environment
virtualenv ~/odoo-10.0 source ~/odoo-10.0/bin/activate
Install odoo requirements
cd odoo pip install -r requirements.txt
Now create a test database and fire up your odoo instance.
createdb odoo-test ./odoo-bin -d odoo-test
How to fix "Warning! Your environment specifies an invalid locale"
Do you see the below notice after installing a fresh ubuntu...
WARNING! Your environment specifies an invalid locale. This can affect your user experience significantly, including the ability to manage packages. You may install the locales by running: sudo apt-get install language-pack-UTF-8 or sudo locale-gen UTF-8 To see all available language packs, run: apt-cache search "^language-pack-[a-z][a-z]$" To disable this message for all users, run: sudo touch /var/lib/cloud/instance/locale-check.skip
Feed in the below command into your terminal to get rid of it
sudo apt-get install language-pack-en language-pack-en-base echo "export LANGUAGE=en_US.UTF-8 export LANG=en_US.UTF-8 export LC_ALL=en_US.UTF-8">>~/.bash_profile
Well Ordering Principle - Negative numbers
Every nonempty set of non-negative integers has a least element.
First question that comes to my mind is why non-negative. The definition doesn't clearly states whether the set is finite or non finite. But every finite set clearly have a minimum element, hence the principle is interesting only if the subsets (of integers) are arbitrary. For a infinite subset of negative integers, we cannot identify a least element, for obvious reasons. Hence the non-negative.
Upgrading MySQL 5.5 to 5.6 in Ubuntu
Download MySQL APT Repository .deb file. Click Here. This will require you to login to MySQL website, in case of remote systems, you'll need do download it in your local machine and copy to any accessible path in remote system.
Install the downloaded package with the following command. Say your filename is mysql-apt-config_0.5.3-1_all.deb, run the following command.
sudo dpkg -i mysql-apt-config_0.5.3-1_all.deb
It'll trigger a popup. Select Server and choose 5.6, then select Apply.
Update the package list
sudo apt-get update
Upgrade MySQL
sudo apt-get install mysql-server
Jetbrains PHPStorm 10 Full Version Hack
After installation, PHPStorm will prompt for Registration.
Choose License Server
Enter http://idea.lanyus.com/
Click OK
I found this here. Out of all odds, this works.
Best method to default variables in php if not set
This neat little trick will work from PHP 5.3 onwards.
$sinceTimestamp = $request->input('since')?:time(); $limit = $request->input('limit')?:10;
Since PHP 5.3, it is possible to leave out the middle part of the ternary operator. Expression expr1 ?: expr3 returns expr1 if expr1 evaluates to TRUE, and expr3 otherwise.
Laravel 5 Custom Validation
Laravel’s Validator::extend() method takes a 3rd parameterfallback_message, which is not mentioned in the docs. Just in case, the validator doesn’t provide a custom message for your rule, this message will be shown instead.
Validator::extend(‘unique_police’, ‘App\CoreValidator@validateUniquePolice’, 'This :attribute is already used. Please try another.');
Increase Weblogic 12c Heap size
Go to the domain home folder. This is where your startWeblogic.sh / startWeblogic.cmd file is present.
In Windows Platform
Open bin/setDomainEnv.cmd
Find the line where WL_HOME is set. In my case...
set WL_HOME=D:\Oracle\Middleware\Oracle_Home\wlserver
Insert following lines above it
@REM Setting USER_MEM_ARGS set USER_MEM_ARGS=-Xms1024m -Xmx2048m -XX:PermSize=128m -XX:MaxPermSize=512m
In Linux / Unix Platform
Open bin/setDomainEnv.sh
Find the line where WL_HOME is set.
WL_HOME="/home/user1/Oracle/Middleware/Oracle_Home/wlserver"
Insert following lines above it
# Setting USER_MEM_ARGS USER_MEM_ARGS=-Xms1024m -Xmx2048m -XX:PermSize=128m -XX:MaxPermSize=512m export USER_MEM_ARGS
Setting up Magento in Nginx PHP-FPM server
If you haven't installed LEMP stack with phpMyAdmin, follow this tutorial.
If you haven't already created a virtual host for this new domain (say mystore.com), follow this tutorial. In the /var/www folder, you might have created the folder for mystore.com. You'll delete it for now.
rm -r mystore.com
Download latest magento from Magento server and place the zipped file in /var/www. I'll download Magento 1.9.1.0 version from their server via wget. Unzip it.
wget http://www.magentocommerce.com/downloads/assets/1.9.1.0/magento-1.9.1.0.zip unzip magento-1.9.1.0.zip
A new folder magento will be created. Rename it to your domain name (as configured in the virtual host file)
mv magento mystore.com
Now edit your nginx vhost file to support magento.
sudo nano /etc/nginx/sites-available/mystore.com
Change it to the below contents. Make sure you replace mystore.com with your domain name.
server { listen 80; server_name mystore.com; root /var/www/mystore.com; index index.php index.html; access_log /etc/nginx/logs/mystore.access.log; error_log /etc/nginx/logs/mystore.error.log; location / { try_files $uri $uri/ @handler; expires 30d; } location /app/ { deny all; } location /includes/ { deny all; } location /lib/ { deny all; } location /media/downloadable/ { deny all; } location /pkginfo/ { deny all; } location /report/config.xml { deny all; } location /var/ { deny all; } location /var/export/ { auth_basic "Restricted"; auth_basic_user_file htpasswd; autoindex on; } location @handler { rewrite / /index.php; } location ~ .php/ { rewrite ^(.*.php)/ $1 last; } location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } rewrite ^/minify/([0-9]+)(/.*.(js|css))$ /lib/minify/m.php?f=$2&d=$1 last; rewrite ^/skin/m/([0-9]+)(/.*.(js|css))$ /lib/minify/m.php?f=$2&d=$1 last; location /lib/minify/ { allow all; } gzip on; #gzip_comp_level 9; gzip_min_length 1000; gzip_proxied any; gzip_types text/plain application/xml text/css text/js application/x-javascript; }
If you don't already have the logs folder in nginx, you can create it.
sudo mkdir /etc/nginx/logs
Now restart the server
sudo service nginx restart
If everything goes fine, you can navigate to mystore.com in your favorite browser. You'll be welcomed with the Magento installation screen.
Prior to the installation, you'll need to make few folders writable.
cd /var/www/mystore.com chmod -R 777 app/etc chmod -R 777 media/
Also you'll need to install php curl extension.
sudo apt-get install php5-curl
Create new virtual host in Nginx PHP - FPM Server
We'll organize all our vhosts in a common folder, for Ubuntu we'll take /var/www as the default one. We'll create a new virtual host for the domain mydomain.com.
cd /var/www
Now we need to make sure the current user has enough privileges to edit the above folder. Add the user to www-data group and give permission to the group www-data for making modifications on this folder.
sudo adduser $USER www-data sudo chown -R www-data:www-data /var/www sudo chmod -R g+rw /var/www
You'll need to logout and login again for the permissions to take effect. After logging in, create new folder for our domain.
mkdir mydomain.com
Before placing any php files inside the folder, you'll need to setup a new virtual host in nginx.
cd /etc/nginx/sites-available/ sudo nano mydomain.com
Copy the following in this file.
server { listen 80 default_server; root /var/www/mydomain.com; index index.php index.html index.htm; server_name mydomain.com; location / { try_files $uri $uri/ =404; } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root /var/www/mydomain.com; } location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
Now you'll need to symlink this file to Enabled Virtual Hosts.
ln -s /etc/nginx/sites-available/mydomain.com /etc/nginx/sites-enabled/mydomain.com
Restart the nginx server
sudo service nginx restart
Let's create a new index.php file in our root folder
cd /var/www/mydomain.com sudo nano index.php
Insert the following lines
<?php phpinfo(); ?>
If you have already mapped mydomain.com to your server, go to mydomain.com in your favorite browser and you'll be welcomed with a php information page.
Install Nginx, PHP FPM, MySQL and phpMyAdmin in Ubuntu 14.04 server
In this guide, i'll demonstrate how to install a LEMP stack on an Ubuntu 14.04 server.
Log into your server as a normal non root user with sudo privileges (You can google how to get if you don't have one).
Install nginx
We'll setup nginx for serving contents through our server.
sudo apt-get update sudo apt-get install nginx
Nginx is configured to start running upon installation. You can test the server by entering your Server's public IP address in your web browser. If you dont have a public ip address, you can use curl utility.
sudo apt-get install curl curl localhost
You'll see some html output in the shell. Good to go.
In the browser you'll see the below output.
Install MySQL
Now we need to install MySQL, a DBMS to store and manage data.
sudo apt-get install mysql-server
You'll have to provide the root password for MySQL server.
Tell MySQL to generate directory structure for storing data files.
sudo mysql_install_db
Next run a simple utility to modify some insecure defaults.
sudo mysql_secure_installation
Keeping hitting ENTER key to remove the unsafe default settings.
Install PHP
Ubuntu package for PHP doesn't contain the latest PHP packages, so you need to install it from an external repository.
sudo locale-gen en_US.UTF-8 export LANG=en_US.UTF-8 sudo add-apt-repository ppa:ondrej/php5 sudo apt-get update sudo apt-get upgrade sudo apt-get install php5-fpm php5
If you don't have add-apt-repository binary do the following:
sudo apt-get install software-properties-common python-software-properties
And press ENTER to continue when prompted.
Now install php and also the mysql extension for php.
sudo apt-get install php5-fpm php5-mysql
We now have our PHP components installed, but we need to make a slight configuration change to make our setup more secure.
Open the main php5-fpm configuration file with root privileges:
sudo vim /etc/php5/fpm/php.ini
Search for string cgi.fix_pathinfo by pressing / and then enter given string. Change the line to look like
cgi.fix_pathinfo=0
Now edit the default vhost file located in sudo nano /etc/nginx/sites-available/default
sudo nano /etc/nginx/sites-available/default
Modify the contents so it includes processing for php files also (via php5-fpm). Given below is a sample vhost configuration.
server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; root /usr/share/nginx/html; index index.php index.html index.htm; server_name localhost; location / { try_files $uri $uri/ =404; } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
Install phpmyadmin
Install phpmyadmin from Ubuntu packages. Enter your MySQL root password when it prompts for.
sudo apt-get install phpmyadmin
In order to access phpmyadmin, you need to make it available in the web root. Create a symbolic link phpmyadmin inside the web root folder pointing to phpMyAdmin's installation location.
sudo ln -s /usr/share/phpmyadmin/ /usr/share/nginx/html/phpmyadmin
Now you'll be able to access phpmyadmin @ http://your-server-ip/phpmyadmin
Using Grunt tasks with laravel - Part 1 - Bower Install Plugin
Change to laravel's root directory, initialize npm with the following command
npm init
Add grunt as dev dependency.
npm install grunt --save-dev
Setup bower for front end package management.
bower init
Now change bower configuration, so the bower files are loaded into public folder of the larevel project. Create a new file .bowerrc in the root folder with the following contents.
{ "cwd": "./", "directory": "public/bower_components" }
Install grunt's bowerInstall plugin.
npm install grunt-bower-install --save-dev
Save Gruntfile.js file in the root directory with the following contents. If you already have an existing Gruntfile then make modifications to include the bowerInstall task.
module.exports = function(grunt){ grunt.initConfig({ bowerInstall: { target: { src: [ './app/views/layouts/master.blade.php' ], cwd: './public/', dependencies: true, devDependencies: false, exclude: [], fileTypes: {}, ignorePath: '../../../public', overrides: {} } } }) grunt.loadNpmTasks('grunt-bower-install'); }
In the above snippet, the target\src attribute for bowerInstall specify the blade file where bower assets are included automatically. You can specify multiple layout files here. Also the ignorePath is important, otherwise the injected path to asset will be relative to the layout file(s), so here we're blindly removing that extra path from injected code.
Now we need to tell Grunt where to inject those asset references in the generated code. This is done by special comments in our blade files.
For css injection, add the following code in your template. Grunt will insert the link tag within it.
<!-- bower:css --> <!-- endbower -->
Similarly for js files.
<!-- bower:js --> <!-- endbower -->
That's the end of the setup. Let's add few dependencies via bower and run the grunt task.
bower install bootstrap --save grunt bowerInstall
Open your layout file to see the injected code.
If you like my post, you should follow me in twitter here.
Happy coding :)
Displaying any date with time in Magento templates
To convert a datetime field from MySQL to a human readable long date time format in Magento templates, use the following function.
echo $this->formatTime($yourMysqlDateTime, "long", true);
Set timestamp field value in Magento
When saving data to a model, developers often encounter situation where they'd need to save current timestamp. Magento introduced Varien_Db_Ddl_Table::TYPE_TIMESTAMP for saving a field as Mysql's timestamp datatype.
Assuming you've a column with name as udpated_at in your model, write as following to save the current timestamp.
... $model->setUpdatedAt(Mage::getSingleton('core/date')->gmtDate()); ...