Posts

Showing posts with the label cool

Preparing for PyCon 2016

Image
Alright, I will attend PyCon2016 in Portlan, Oregan: https://us.pycon.org/2016/ It's time to plan: Flight ticket: Savings or do some projects. Accomodation: AirBnB VISA: take 1-2 months. Genius!!!!!!

Excel to list of dictionaries in Python

This is a pretty neat python snippet I wrote to read an Excel (xlsx) file and convert its data into a list of dictionaries: Note: you need to install the openpyxl module before you can use the snippet $ sudo pip install openpyxl So, you can use the snippet as following: >> from excel_utils import excel_to_dict >> data = excel_to_dict('/path/to/excel/file.xlsx', ['col1', 'col2', 'col3']) >> data[0] {'col1': u'Genius',  'col2': u'Super',  'col3': u'Awesome'} Cool huh? Reference:   https://automatetheboringstuff.com/chapter12/

How to set course format for multiple courses in Moodle

It's pretty cool using MOOSH command line tool of Moodle. You can set course format to topics for multiple cources in Moodle by running this command: moosh course-config-set category 7 format topics Just awesome!!! Reference: http://moosh-online.com/commands/

Sort table of links with Tablesorter jQuery plugin

Assuming you have a table of links (link a portal) in your website like the following: <table class="tablesorter" id="tbl1"> <thead> <tr> <th> Faculty </th> </tr> </thead> <tbody> <tr> <td><a href="#link1">A link</a></td> </tr> <tr> <td><a href="#link2">G Link</a></td> </tr> <tr> <td><a href="#link3">H Link</a></td> </tr> <tr> <td><a href="#link4">B Link</a></td> </tr> <tr> <td><a href="#link5">K Link</a></td> </tr> <tr> <td><a href="#link6">U Link</a></td> </tr> <tr> <td><a href="#link7">C Link</a></td> </tr...

My first 3D printed model

Image
Oh right, this is my first 3D printed model ever: These are things that good and not good about this Micro 3D printer at this moment: Good: The printer is small, has elegant design It's not only easy to get up and running, but also so intuitive to operate Quiet when printing The software is quite easy and simple. The printed object is pretty accurate in size and shape (except for the distorted head of the little minion) Not good: The M3D software does not support Linux yet which made me to go all over my friend house and borrowed his windows computer. For some reasons, the printed model is distorted at the top even though I only printed it at the medium level (It took more than 3 hours). Seem like the complex models like the one I printed here is hard for M3D. The result is not so good as I expected. Conclusion: I guess I need to polish the printed model to remove the protection material surround the object. I will need to upg...

Cleaning up your WordPress Multisite instance with wp-cli

At some points in life, your WordPress Multisite will become too big and needs to be cleaned up, things like spam comments, revisions, transients... And of-course, you don't want to go blog by blog to clean up all those things. It may take days or weeks if you have > 1000 sites like mine. Here is your savior: WP-CLI WP-CLI is a command line tool which can help you manage your WordPress site flawlessly (:D). This blog post will show you how to use wp-cli to clean up your WordPress Multisite including: 1. Transients: Create a shell script inside your WordPress dir root: $ cd /path/to/wordpress/root $ sudo nano clean_transients.sh #!/bin/bash for url in $(wp site list --field=url --allow-root) do   echo $url #used for progress purposes   wp transient delete-all --url=$url --allow-root done $ sudo chmod +x clean_transients.sh $ sudo ./clean_transients.sh --allow-root 2. Spam comments: $ cd /path/to/wordpress/root $ sudo nano clean_comments.sh ...

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) {         ...

New "car"

Image
I just bought a new bicycle and started riding to work every day for a week. I will have to ride more than 20 km a day. It's pretty awesome huh? Gonna loose some weight! \m/