Posts

Showing posts from September, 2015

Sophie's world

Image
I used to think philosophy is a boring subject until one day I found Sophie's World, a book by Jostein Gaarder. From the moment I finished that book, I became interested in Philosophy. In Sophie's World, the author teaches readers about all the main ideas from the ancient to the modern time via a story of a girl name Sophie. Everything begins when one day fourteen-year-old Sophie Amundsen comes home from school to find in her mailbox two notes, with one question on each: "Who are you?" and "Where does the world come from?". After that, Sophie goes on a journey to answer those questions by using the philosophy she learnt along the way. At the end of Sophie's adventure, you will notice that the whole history of philosophy was painted vividly and impressively. When I reached the final page of the book, I suddenly realized everything in the world is still a mystery and has a lot of questions need to be answers. And the only way is through philosophy

Adding additinal data into each Google Form response when submitting using Google Apps Script

This was another Google Form challenge I got this week. The school want to add the department code into the user's response right after she/he submits her/his course selection from the Google Form. For example, if the user select course ABC and submit the form, the responses spreadsheet will have a new line with the department code filled in automatically: timestamp,course,dept ..,ABC,departmentcode01 What I had done to get it done are: 1. Like the previous Google Form challenge , I had to prepare a google spreadsheet contains all the courses and their department codes: course,dept ABC,departmentcode01 Physics,departmentcode02 ... 2. In the form's editor mode, select Tools >> Script editor, and write a script containing four functions: A function to read the data spreadsheet (course/departmentcode):   sheet_to_list ( spreadsheetid , sheetname )  A function to search through the response spreadsheet and get the selected course: get_feedback_course

Another quote of the day

"People who are afraid of death, are afraid of life." ~" Hector and the search for happiness "

Quote of the day

"Avoiding unhappiness is not the road to happiness." ~" Hector and the search for happiness "

Generating Google Form from Google Spreadsheet using Google Apps Script

Google Form is such a great tool for us to create surveys with a great web interface. But, the thing is even with the cool drag-and-drop features, It's still a pain in the ass to generate forms from a mass amount of data (questions and choices). That's where Google Apps Scripts comes into its usefulness. Here is a case study from my real life experience: Earlier this week I had a chance to tinkering around the apps scripts to help my school create a survey with a set of data stored inside an excel file. The final goal is to create a form in which students give feedback to each of their teachers on each courses. So the excel data looks like this: Teachers sheet: this sheet contains 3 columns, each column is a list of all the teachers of each schools (elementary, middleschool and highschool) es,ms,hs teacher1,teacher2,teacher3 teacher6,teacher7,teacher8 ... Courses sheet: the courses sheets is storing name of the courses each teacher is teaching teacher1,teacher2,t

Google spreadsheet data to dictionary using Google Apps Script

Another great snippet I wrote this morning:

Google spreadsheet data to list using Google Apps Script

Here is the snippet I just wrote, pretty convenient:

Get keys of a dictionary in Google Apps Script

To get all the keys of a dictionary in Google Apps Script or Javascript, do as following: var mydata = {'key1': value1, 'key2': value2}; var keys = Object.keys(mydata);

Foreach in Google Apps Script

In Google Apps Script, you can do the foreach loop as the following example:  var headers = ["super", "genius", "awesome"];  for each (var header in headers) {        Logger.log(header);  }

Foreach in javascript

If you wanna use foreach to loop through an array (list) in javascript, do as the following example: var myarray = ["genius", "super", "god"]; myarray. forEach (function(value, index){     console.log(index + ": " + value); }); the result will be: 0: genius 1: super 2: god Tested in Chrome 45.

Link to add an event to your google calendar

This is a common functionality you want to add to your event website that will help your users add the event schedule to their Google calendar. Simply using this following html syntax: <a href="http://www.google.com/calendar/event? action=TEMPLATE &text=[event-title] &dates=[start-custom format='Ymd\\THi00\\Z']/[end-custom format='Ymd\\THi00\\Z'] &details=[description] &location=[location] &trp=false &sprop= &sprop=name: &ctz=[timezone]" target="_blank" rel="nofollow">Add to my calendar</a> For Example: <a href="https://www.google.com/calendar/render?action=TEMPLATE&text=Vietnam+Tech+Conference+2017&dates=20170311/20170313&details=For+details,+link+here%3a+http://vietnamtechconference.org&location=Saigon+South+International+School,+Tân+Phong,+Quận+7,+Ho+Chi+Minh+City,+Vietnam&output=xml&ctz=Asia/Ho_Chi_Minh" target="_blank" rel="nofollow&qu

Debug NGINX configuration

Use this command to debug or test your NGINX configuration: nginx -t -c /etc/nginx/nginx.conf

Texts in SVG do not show up in browsers

If you create a SVG vector image using Inkscape with text(s) you may encounter this: all the texts do not show up in any browser. It is because Inkscape using flowed-text by default which is an un-finished function and is not implemented yet in any other vector renderers (like the browsers). So, what you can do now is to convert those texts into regular texts or non-flowed-text by: 1. Select the text(s) 2. In Text menu, select Convert to text References: [0]  https://bugs.launchpad.net/inkscape/+bug/747441 [1]  http://wiki.inkscape.org/wiki/index.php/FAQ#What_about_flowed_text.3F

Bring on the Learning Revolution by Ken Robinson

Image

Quote of the day

"The secret of happiness is to see all the marvels of the world, and never to forget the drops oil on the spoon." ~"The Alchemist", Paulo Coelho .

Alive Inside

Image

Auto rotate and autoresize images in mass with Python and PIL

This is what you need: For example, rotate all the images in /path/to/images/directory and resize them to 200x300 (W x H) $ python img_utils.py --dir /path/to/images/directory --resize 200 300

Transposing csv data using Python

Here is the case: You have this original csv data: name,course,number A,Genius,12 A,Super,13 B,Goddess,15 C,The Man,17 C,The Woman,10 C,Harvard,11 C,StanFord,18 and you want to create another csv file that uses name 's values as columns and group the course 's value as rows: A,B,C Genius,Goddess,The Man Super,'',The Woman '','',Harvard '','',StanFord Here is what I did to achieve that: 1. Read the original csv file and convert it into a list of dicts 2. Transpose the list by grouping the name column: Get all the name's value group_cols = [] for o in original_list: if o[group_col_name].strip() not in group_cols: group_cols.append(o[group_col_name].strip()) For each of the name, loop through the original list and append the according course's value to a tmp list (with the name as the first item), then add all of the tmp lists to a new list: thelist = [] for c in group_co

Equalizing lists's length using Python

Assuming you're having a list of lists which vary in length and you want to make every list have the same length (with the length of the longest list). One simple solution is to append the children lists with empty strings or None. For example: [[1,2], [4,5,6], [6,7,8,9,10]] => [[1,2, '', '', ''], [4,5,6, '', ''], [6,7,8,9,10]] Solution #1 - Here is the snippet:

Sorting select options in alphabet order

Pretty handyyyy: Reference: http://stackoverflow.com/questions/12073270/sorting-options-elements-alphabetically-using-jquery

Getting max length of list of lists in Python

Here is the handy snippet:

Unpacking argument lists in Python

What I want to achieve is to transpose the list of list or tupple: original = [('First', 1, 3, 4), ('Second', 4, 5, 6)] to transposed = [('First', 'Second'), (1, 4), (3, 5), (4, 6)] With itertools.izip I can solve my problem: from itertools import izip transposed = izip(original[0], original[1]) But, what if my original list contains 1000 lists/tuples? Fortunately, in Python, you can unpack the list as arguments. So, what I need to do is just: transposed = izip(*original) Pretty amazing huh? References: [0] https://docs.python.org/2/tutorial/controlflow.html#tut-unpacking-arguments [1] http://stackoverflow.com/questions/4112265/how-to-zip-lists-in-a-list

HUMAN

Image
"Filmmaker and artist Yann Arthus-Bertrand spent 3 years collecting real-life emotional stories from more than 2,000 women and men in 60 countries. Those emotions, those tears and smiles, those struggles and those laughs are the ones uniting us all." Official website: https://humanthemovie.withgoogle.com/ VOL.1 VOL.2 VOL.3

Fetching external RSS feeds with jQuery and Google Feed API

Sometimes, you just want to fetch the rss feeds from an external site without touching any server code. jQuery and Google Feed API will save your day. rss_parser.js: Then, in your html page or post, use this: <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ></script> <script src="/path/to/parser.js"></script> <div id="myrss" class="box"></div> <script type="text/javascript">       $(function(){             parseRSS('http://mywebsite.com/feed/', '#myrss');       }); </script> The feeds will be inserted into myrss div. Reference:   https://developers.google.com/feed/v1/reference

Executing shellscript with administrator (sudo) privileges (GUI) in Mac OSX using AppleScript

You created an executable shellscript that requires sudo or admin privileges in Mac OSX to do something like install printers, change DNS server... It's not difficult, you just need to open the terminal, grant the script file the executable permission, then run it. But the thing is the terminal interface may scare the shit out of a normal user. What can you do about that? OK, AppleScript is your savior. Write a wrapper script using AppleScript to call your genius shell. With the AppleScript you can popup a beautiful window (GUI) asking for administrator password. Here is an example: myshellscript.sh: #! /usr/bin/bash sudo networksetup -setdnsservers Wi-Fi 8.8.8.8 Basically, my example do the following: 1. Upload your shellscript somewhere public that allow you to download the script using curl. For example: http://mywebsite.com/myscript.sh 2. Using AppleScript to grant executable privileges to the shellscript with " with administrator privileges ": d

#600 Fix Wordpress's admin menu issue in Chrome 45

Image
If you noted, the admin menu of WordPress (4.3) is messed in Chrome (v45): According to a StackOverflow post there is a known bug in chrome (more info here ). The source of the problem stems from Slimming Paint which is enabled by default in Chrome 45. Disabling slimming paint fixes the issue. To disable this feature, visit chrome://flags/#disable-slimming-paint in Chrome and Enable the Disable slimming paint option, and make sure the other two Enable options are disabled because they will override the Disable option. Hopefully, it will be fixed in Chrome  version 47 . For now, you can do as following to solve this issue: add this in your template's functions.php (single site) or in mu-plugins/functions.php (multisite): function admin_menu_fix() {     echo '<style>     #adminmenu { transform: translateZ(0); }     </style>'; } add_action('admin_head', 'admin_menu_fix'); References: [0] http://stackoverflow.com/questions/

Quote of the day

“The limits of my language means the limits of my world.” ~ Ludwig Wittgenstein .

Mass enroll users into a Moodle course

Image
To mass enroll users into a Moodle course, you can use the upload users csv file method as following: Assuming: All the student accounts are in Active Directory and being used to login into Moodle All student (in the csv file) will be enrolled into my-course-short-name course. 1. Prepare the csv file with student information, let's call it students.csv: idnumber,lastname,firstname,email,username,auth,course1,type1,role1,enrolstatus1 102340,Joe,Student One,jstudent1@my.moodle,jstudent1,ldap,my-course-short-name,1,student 102342,Joe,Student Two,jstudent2@my.moodle,jstudent2,ldap,my-course-short-name,1,student ... 2. Go to Site administration > Users > Accounts > Upload users to upload students.csv 3. In the Upload users preview screen, config as following: 4. Click Upload users to finish.

Showing student custom field data in classattendance page in PowerSchool Teachers

I was trying to display some custom field data (I will take ssis_student_nickname as an example in this article) in the classattendance.html page in PowerSchool Teachers. But, to be honest, I'm not sure about the customization syntax of PowerSchool. I couldn't make it work with this following syntax: ~([01]ssis_student_nickname) or ~([Students.U_STUDENTSUSERFIELDS]ssis_student_nickname) As fas as I acknowledged, the classattendance page accessing the attendance database using some javascript. So, in the end, I have to do some hack to display the custom field in that page. Here is the details: 1. Add an additional column in the page, and name it: ...              <th align="left" class="cvDemarcation">~[text]psx.html.teachers.classattendance.students[/text]</th>             <th class="cvDemarcation">Student Nick Name</th> ...             <tr class="studentrow">                 <td class=&

Mass update/import setting (option) in WordPress Multisite using WP-CLI

Ok, just put this shell script inside your wordpress's root: Then run it. For example, I want to update the tadv_settings (TinyMCE Advanced) to all the blogs in my network: /my/wordpress/root/$ ./update_setting.sh tadv_settings /path/to/my/settings.txt The setting file look like this, settings.txt: {"toolbar_1":"fontselect,fontsizeselect,forecolor,backcolor,bold,italic,underline,blockquote,wp_code,bullist,numlist,alignleft,aligncenter,alignright,alignjustify,link,unlink","toolbar_2":"formatselect,undo,redo,table,media,image,hr,subscript,superscript,strikethrough,outdent,indent,pastetext,removeformat,charmap,wp_more,emoticons,code,fullscreen","toolbar_3":"","toolbar_4":"","options":"advlist,contextmenu,advlink,menubar,image","plugins":"anchor,code,insertdatetime,nonbreaking,print,searchreplace,table,visualblocks,visualchars,emoticons,advlist,link,contextmenu&