Posts

Showing posts from July, 2015

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

Change Atom's title bar text using custom-title plugin

Image
To modify the Atom's title bar text with your own pattern, you can use this plugin: custom-title In Atom, go to Settings >> Install >> type custom-title in the search bar and install the package. After you have installed custom-title successfully, go to Settings >> Packages >> click custom-title's Settings button and change the title pattern to whatever you want using its provided syntax. For example, I want the title bar display full file's path, I will use this following template: <%= filePath %>

Change the scroll-top behavior of the ckeditor of MindTouch Core 10.1.3

I added a fixed top navigation bar to the theme of my MindTouch Core instance and it overlays the toolbar of the ckeditor when I scroll (because both of them are supposed to be at the top when scrolling). I have to fixed that by hacking into the core javascript of MindTouch for ckeditor: 1. First, we need to beautify the following file (because it was minified): Copy content of mindtouch.js   /path/to/dekiwiki/deki/plugins/page_editor_ckeditor/ckeditor/mindtouch.js Go to  http://jsbeautifier.org/  and beautify the javascript, copy it. Replace the minified content with the beautify one into mindtouch.js 2. Next, go to line 737 and change as following:                 if (g < l) {                         // this will                          j = g - i + 55;         ...

Remove the ending character (delimiter) of the breadcrumb in MindTouch Core 10.1.3

To remove the ending character (the delimiter, " > ") of the breadcrumb in MindTouch Core (v10.1.3), you can do the following: 1. Open this file /path/to/dekiwiki/includes/Skin.php: $ nano /path/to/dekiwiki/includes/Skin.php 2. Go to line 168 and remove the special character output (in red color):         function getHierarchy() {                 $parents = $this->getParents();                 $rootNode = count($parents) == 1;                                  //special case; when you're on the home page, let's add an extra delimiter at the end, so it doesn't look like freestanding text                 if ($rootNode) {                         $parents[] = '';         ...

Adjust the width of the side panel of MindTouch Core 10.1.3

If you want to adjust the width of the side panel of MindTouch Core (v10.1.3), you need to do a little hack: 1. Open this file /path/to/dekiwiki/deki/plugins/nav_pane/nav_pane.php: $ nano   /path/to/dekiwiki/deki/plugins/nav_pane/ nav_pane.php 2. Go to line 66, change the number (in red color) to whatever you like: ...         $width = isset($wgNavPaneWidth) ? $wgNavPaneWidth : 2600 ; ... Neat!

Check if an element is shown with jQuery

Quite easy: jQuery('#some-element-id').is(':visible'); Cool!

Ex Machina drawing

Image
here

Collaboration, a documentary film

Image

Using Google Translate in your command line

It sounds pretty cool huh? Yes, it is. This project brings the translation service of Google down to your command line: Name: Translate-Shell Git repo: https://github.com/soimort/translate-shell 1. Install translate-shell the easiest way: $ cd /some/path/ $ wget git.io/trans $ chmod +x ./trans 2. Add /some/path/ to your PATH: $ nano ~/.bashrc ... PATH="/some/path:$PATH" $ source ~/.bashrc 3. Start translating, example: $ trans fr:vi "je t'aime" the result will be: je t'aime tôi yêu bạn Translations of je t'aime [ Français -> Tiếng Việt ] je aime te     tôi yêu bạn, anh yêu em, tôi yêu em, I love you, Em yêu anh For more command, please read the instructions at:  http://www.soimort.org/translate-shell/

How to make the Atto editor of Moodle always expanded

Image
Be default the Atto HTML editor is collapsed. It would  be helpful if we can make it expanded so the users don't have to click the Show/Hide button all the time. And here is how: Go to Site administration  > Plugins  > Text editors  > Atto HTML editor  > Atto toolbar settings , scroll to the Toolbar config box and remove the setting ' collapse = collapse '. Save the changes.

Get WordPress Multisite blog_id by blog's path using wp-cli

You have a csv file has this format (mycsv.csv): path,some_field somepath,some_value anotherpath,another_value ... and you want to get the blog_ids of those path(s). This following bash shell will help you to get blog_ids by taking advantages of wp-cli, get_blogid_from_url.sh: $ chmod +x get_blogid_from_url.sh $ ./get_blogid_from_url.sh mycsv.csv myblog.com /wordpress/path > result.csv The result will be something like: 546,myblog.com/somepath/ 456,myblog.com/anotherpath/ ...

Echo new line in bash shell

When echoing strings with new line character ("\n") you want the shell translates it for you (actually displaying text in new line not just the character), you can do as following: A string: mystr="Good morning.\nHow are you?\nI'm fine." echo -e "$mystr" And the result will be: Good morning. How are you? I'm fine. Result of a command: sites=$(wp site list --allow-root --path=/var/www/ --fields=blog_id,url --format=csv) echo "$sites" Note that quoting (") does matter to preserve multi-line values. the result will be something like this: 566,myblog.com/somepath/ 677,myblog.com/anotherpath/ ... Reference:   http://stackoverflow.com/questions/8467424/echo-new-line-in-bash-prints-literal-n

String operations with wildcard in bash shell

To compare strings with wildcard in bash shell you can do as below (there's different between single and double brackets): if [[ $a == z* ]] ...   # True if $a starts with an "z" (pattern matching). if [[ $a == "z*" ]] ... # True if $a is equal to z* (literal matching). if [ $a == z* ] ...     # File globbing and word splitting take place. if [ "$a" == "z*" ] ... # True if $a is equal to z* (literal matching). Reference:   http://www.tldp.org/LDP/abs/html/comparison-ops.html

Bash shell to find and replace text in multiple files

The snippet below will find and replace the string 'original string' with 'new string' in all the csv file inside /example/myfolder/ find /example/folder -name \*.csv -exec sed -i "s/original string/new string/g" {} \; Pretty cool!

Quote of the day

"Nowadays people know the price of everything and the value of nothing." ~Oscar Wilde.

Steve Jobs 2015

Image

Assigning roles to users in Moodle based on their profile data using php script

In case you want to allow some particular blocks to be seen only by a particular group of users in your Moodle, you can do as below: Note: assuming you've already created all the user accounts in your Moodle. 1. Categorize your users using some fields like department or description: For example, I have Middle School Students and High School Students. Each of the students has Graduation Year information stored in the department field of the user profile. I will then use that field to determine which school they are studying now: Student Number 1's department: 2015 class => High School Student Number 2's department: 2021 class => Middle School The below snippet is pretty handy to identify which school a student is studying based on her graduation year: <?php function class_to_grade_level ($class_of) { // you may want to change the timezone date_default_timezone_set('Asia/Ho_Chi_Minh'); $grad_year = intval($class_of); $curr...

Make Moodle's Custom Menu Item URLs to open in a new window

Be default, when you click the menu item you add in Moodle, you will be redirected to that link. If you want the menu open in a new window, you can do the following (example): In Site administration -> Appearance -> Themes -> Theme settings (or http://your.moodle.url/admin/settings.php?section=themesettings), in the "Custom menu item" box: Moodle new window|http://www.moodle.org/ " target="_blank" But it fails if the URL has special characters like: Moodle new window|http://www.moodle.org/ ?param1&param2 " target="_blank"