Posts

Showing posts from May, 2015

Generate static html file from WordPress page

OK, Is your WordPress page rarely get updated, let's say once a day or a week. If so, you can use the following technique to reduce the load (queries) to the database especially in multisite deployment: Write a script to generate static content with updates from the database only once a day or a week. Then your users will access this static page instead of the heavy loading WordPress page with hundreds of database queries. 1. Create a wordpress template file wp_template.php (place it in your template root, e.g. /var/www/wordpress/wp-content/themes/mythemes/) which will get data from the database. For example: 2. Create a crontab to run this command every day at 1AM to generate the static html file in the web root: /usr/local/bin/blog_static_gen.sh: #! /bin/bash $ cd /var/www/wordpress/wp-content/themes/mythemes $ php wp_template.php > /var/www/wordpress/wp_template.html crontab: 0 1 * * * /usr/local/bin/blog_static_gen.sh 3. Then you can access the static co

Digital Forensics resources

Here are some useful links relates to Digital Forensics: http://isis.poly.edu/kulesh/forensics/list.htm https://staff.washington.edu/dittrich/misc/forensics/ https://staff.washington.edu/dittrich/forensics.html http://digital-forensics.sans.org/blog/2010/08/20/getting-started-digital-forensics-what-takes/ http://www.isfs.org.hk/publications/ComputerForensics_part1.pdf https://resources.sei.cmu.edu/asset_files/Handbook/2005_002_001_14429.pdf http://en.wikipedia.org/wiki/Digital_forensic_process http://learn.org/articles/Free_Online_Computer_Forensics_Courses_Where_Can_I_Find_Them.html http://study.com/articles/List_of_Free_Online_Computer_Forensics_Courses_and_Classes.html

Getting started with digital forensics

Image
  source: http://www.usainvestigators.com/a-beginners-guide-to-digital-forensics-infographic/

Dynamic grid columns in Bootstrap

So, I want to apply the grid style of Bootstrap to the a number of div tag in my php code . Here is one way to achieve that: 1. Using this javascript snippet in the template: $(document).on("ready", function() {   $.each(['xs', 'sm', 'md', 'lg'], function(idx, gridSize) {     $('.col-' + gridSize + '-auto:first').parent().each(function() {       //we count the number of childrens with class col-md-6       var numberOfCols = $(this).children('.col-' + gridSize + '-auto').length;       if (numberOfCols > 0 && numberOfCols < 13) {         minSpan = Math.floor(12 / numberOfCols);         remainder = (12 % numberOfCols);         $(this).children('.col-' + gridSize + '-auto').each(function(idx, col) {           var width = minSpan;           if (remainder > 0) {             width += 1;             remainder--;           }           $(this).addClass('col-' + gri

Bulk deleting users in WordPress

Image
To delete a whole bunch of users in WordPress you can do the following trick: 1. Click on Screen Option in the User screen and adjust the " Number of items per page: " do a number you want, such as 600. It will show 600 users. 2. Select all the users on the screen. 3. In Bulk Actions drop-down, select Delete , and click Apply

CSV file to PHP array

Here is a pretty cool snippet to read csv file and turn it into a php array: function read_csv($csv_path){ $file = fopen($csv_path, 'r'); while (!feof($file) ) { $lines[] = fgetcsv($file); } fclose($file); return $lines; }

Multilevel drop-down menu in WordPress with Bootstrap 3

To integrate Bootstrap 3 navigation menu to WordPress you can use the following walker class: https://github.com/twittem/wp-bootstrap-navwalker But, the problem is it only allows a single dropdown level to honer BootStrap 3's mobile first philosophy. Fortunately, the guy this blog post had done a little hack to bootstrap and the walker class above to support multilevel drop-down menu: Blog post: http://www.jeffmould.com/2014/01/09/responsive-multi-level-bootstrap-menu/ Github repo: https://github.com/jeffmould/multi-level-bootstrap-menu Basically, what you should do to have a bootstrap 3 style dropdown menu in your WordPress theme are: 1. Copy the  wp-bootstrap-navwalker.php file from the github repo to the theme's root directory 2. Add this style to your theme: .dropdown-submenu{position:relative;} .dropdown-submenu>.dropdown-menu{top:0;left:100%;-webkit-border-radius:0 6px 6px 6px;-moz-border-radius:0 6px 6px 6px;border-radius:0 6px 6px 6px;} .dropdo

Install OpenVAS 8 in Ubuntu 14.04 using PPA

Image
You can install OpenVAS 8 in Ubuntu 14.04 using this ppa: https://launchpad.net/~mrazavi/+archive/ubuntu/openvas $ sudo add-apt-repository ppa:mrazavi/openvas $ sudo apt-get update $ sudo apt-get install openvas You have to update openvas scripts/data after installation with the following commands: sudo apt-get install sqlite3 sudo openvas-nvt-sync sudo openvas-scapdata-sync sudo openvas-certdata-sync sudo service openvas-scanner restart sudo service openvas-manager restart sudo openvasmd --rebuild --progress Login into https://localhost:443 with "admin" as username and password. Done. Pretty easy huh?

Quote of the day

"You gave me purpose!" ~Somebody

Get an image randomly from a directory and display it using PHP and jQuery

Here is how you can get an image randomly from a directory and display it in a webpage using PHP and jQuery: 1. getimage.php: <?php     $files = glob('/path-to-dir/*.*');     $file = array_rand($files);     echo $files[$file]; ?> and call that script with jquery AJAX : 2. index.html: <div id="my-img"> </div> <script> function get_random_image() {    $.ajax({       url: 'getimage.php'        }).done(function( filename ) {            jQuery('#my-img').css('background', 'url('+filename+')');      }); } setInterval(get_random_image, 5000); </script> The background will be replaced by a random image from /path-to-dir/ directory every 5 seconds.

A quick way to fix the "Warning: Missing argument 2 for wpdb::prepare() " error in Wordpress

When using $wpdb->prepare(..) you may got this error: Warning: Missing argument 2 for wpdb::prepare()... Typically It is because you called the prepare function with only the query string. The correct way to do is something like this: $wpdb->prepare( "SELECT * FROM table WHERE id = %d", $id ); But what if the function is called by a plugin written by someone and you don't want to mess with the query. Here is a quick way to fix that: Add null as the second parameter: $wpdb->prepare( "<some query>", null ); References: [0] https://make.wordpress.org/core/2012/12/12/php-warning-missing-argument-2-for-wpdb-prepare/ [1] https://wordpress.org/support/topic/warning-missing-argument-2-for-wpdbprepare-3

Quote of the day

Image
“ If you ' ve created a conscious machine , it's not the history of man . It's the history of gods.” ~Ex Machina.

A pretty neat way to debug WordPress

Image
This morning while trying to debugging a theme I developed for my WordPress blog, I found this pretty cool tool to make the process easier, the WordPress PHP Console: Github repository: https://github.com/barbushin/php-console WordPress repository: https://wordpress.org/plugins/wp-php-console/ Chrome extension: https://chrome.google.com/webstore/detail/php-console/nfhmhhlpfleoednkpnnnkolmclajemef 1. Install the WordPress PHP Console plugin in your WordPress: https://wordpress.org/plugins/wp-php-console/ 2. Setting up: The most important thing you have to do to make it work is setting the password for WordPress PHP Console: 3. Install the Chrome Extension: https://chrome.google.com/webstore/detail/php-console/nfhmhhlpfleoednkpnnnkolmclajemef 4. Start debugging your WordPress: + Open your WordPress site in Chrome + Click the 'key' icon at the end of the address bar and sign in + Then click the Eval console icon which replaces the key icon after

Finally, a pretty good REPL for PHP that I'm looking for

Image
After a while giving up on looking for a good REPL for PHP to make my debugging life easier, I accidentally found this: http://psysh.org/ And OMG it is so good. Things such as autocomplete, history, don't have to put the semicolon at the end of every line!!! I love it!!! Check it out now!!!

Automatically add new created users (by email or ldap login) to a project in Redmine

Alright, just got this to work a couple minutes ago: * I'm using the Redmine's rake to create issues by fetching email messages ( read this ): RAILS_ENV="production" /usr/bin/rake redmine:email:receive_imap host=imap.gmail.com port=993 ssl=1 username=myemailusername@mydomain.com password=myPassword project=helpdesk unknown_user=create no_permission_check=1 no_account_notice=1 Project id: helpdesk Default user role: Customer * If the email address of the sender is not in Redmine's db, it will create a new user with that email. Let call it joeuser . The problem is the new created user was not added to the project ('helpdesk'), so she will not receive any follow-up email messages (any updates of the ticket). So, I have to modify the Redmine's core to add the new user to the helpdesk project with the Customer role: 1. New user created by the Email task: /path/to/redmine/app/models/mail_handler.rb if addr && !addr.spec.blank?

Setting up VNC remote desktop on my BeagleBone Black

Image
Here is how I setup VNC remote desktop on my BeagleBone Black: 0. SSH to the BBB using root user without password: $ ssh root@<BBB's ip address, it's usually 192.168.7.2> 1. Install a Desktop Environment (LXDE) in BBB: # apt-get -y install lxde lxde-core lxde-icon-theme 2. Install x11vnc on the BBB: # apt-get install x11vnc 3. Run the x11vnc with debian user: # su debian $ x11vnc -display :0 -forever The VNC service will run on port 5900 of the BBB. 4. Install and run a VNC viewer such as SSVNC on my Ubuntu machine to remote desktop to my BBB: $ sudo apt-get install ssvnc Enter the ip address of the BBB >> select None >> Connect

How to know if my computer boots using UEFI in Ubuntu

So, I'm just wondering which technology my computer booting with whether it's BIOS or UEFI. Here is the tool that I found useful to help me achieve that goal: efibootmgr. 1. Install efibootmgr: $ sudo apt-get install efibootmgr 2. Check if my computer's using UEFI to boot: $ sudo efibootmgr if the result is as following: EFI variables are not supported on this system. the answer is NO. For more information about UEFI, please read this article:  https://www.happyassassin.net/2014/01/25/uefi-boot-how-does-that-actually-work-then/

Sharing Internet with the BeagleBone Black over its usb network interface

Here is the scenario: * My Ubuntu computer has access to the Internet through wifi (wlan0). * I connect my BeagleBone Black to my host computer using the usb cable, and the usb network is on. * The ip addresses of the usb network connection are: + Ubuntu computer: 192.168.7.1 + BeagleBone Black: 192.168.7.2 * But when I log into the BBB, it cannot go out to the Internet. So, I will attempt to share my Ubuntu's wifi connection to the BBB via the usb network connection: 1. SSH to the BBB: ssh debian@192.168.7.1 2. In the BBB console type the following: sudo ifconfig usb0 192.168.7.2 sudo route add default gw 192.168.7.1 3. In the linux console of host system (Ubuntu) type: sudo su #wlan0 is my internet facing interface, eth1 is the BeagleBone USB connection ifconfig eth1 192.168.7.1 iptables --table nat --append POSTROUTING --out-interface wlan0 -j MASQUERADE iptables --append FORWARD --in-interface eth1 -j ACCEPT echo 1 > /proc/sys/net/ipv4/ip_forw

Articles of the week

These are articles I read this week which were great: The importance of a good night's sleep : http://www.historytoday.com/katharine-craik/importance-good-nights-sleep Katharine A. Craik explains the importance of sleep to the human being and what kind of factors that affect our sleep. Tired of recruiting's broken image, AirBnB rewrites the playbook : http://www.forbes.com/sites/georgeanders/2015/05/06/airbnbs-5-star-recruiting-twist-the-competitive-power-of-nice/ The article started with the story of Joe Gebbia, AirBnB founder, a graphic designer who couldn't get a job.

Quote of the day

"Vision without execution is hallucination." ~Thomas Edison.

My 2015 Spring Break wrap up

What did you do during this Spring Break? Here are several things I accomplished last week: 1. Built the Maker Table for Video Blogging There're still things need to be improved such as: Better camera mount which can be adjustable easily. Decrease or even get rid of the vibration of the camera when filming. Improve the lightning system to have a better image quality. Anyway, It looks pretty neat :D 2. Completed the Seth Godin's Freelancer online course on Udemy: Course URL: https://www.udemy.com/seth-godin-freelancer-course/ Introduction video: Lessons learnt: Seth worked me through many different situations which inspired and prepared me for the freelancer's work. And what I got after finished this course are how I can control my life better as a human being, not just a freelancer, and how I can make a dent in the universe. You should take this course too!

A quick and easy way to change WordPress's SITE URL

This is a quick and easy way to change WordPress's SITE URL without touching the database: Add these lines to your wp-config.php: define('WP_HOME','http://example.com'); define('WP_SITEURL','http://example.com'); Basically, they will force the site to use that address instead. Any config you make in the WordPress Admin Dashboard will not be affected.

How to restore the nginx.conf to default

Sometimes you mess up the nginx.conf of your server just like me a couple days ago, and want to go back to default. Here is how to do it: 1. Move the current nginx.conf to somewhere else or change its name: $ sudo mv /etc/nginx/nginx.conf /etc/nginx/nginx.bk 2. Restore the default nginx.conf using the " force-confmiss " option of dpkg: $ sudo dpkg --force-confmiss -i /var/cache/apt/archives/nginx-common_*.deb 

Seth Godin Freelancer Course's Lecture 65, Exercise 10 - Organize your competitors

Seth Godin Freelancer Course's Lecture 63, Exercise 9 - Leveraging Content

Seth Godin Freelancer Course's Lecture 60, Exercise 8 - Organize and Connect

Seth Godin Freelancer Course's Lecture 50, Exercise 7 - Permission

DIY Maker Table for Video Blogging

Image
This is the Maker Table I just made for my girlfriend this morning. It has a camera mount and a compact fluorescent lamp on the top and 2 more compact fluorescent lamps on the sides. Look pretty neat right?!