POP Keywords: android apache sybase ...

javascript: suffle array (one-line script)

Here is a fantastic way to shuffle an array in javascript: myArray.sort(function() {return 0.5 – Math.random()}); So simple yet so efficient, I love it sources http://css-tricks.com/snippets/javascript/shuffle-array/

wordpress: prevent direct access to file from outside the workflow

Let’s say you don’t want users to access your script file via typing it’s url in the browser, here is a simple way for instance to make sure wordpress framework has been loaded and section is admin section: if (!defined(‘WP_ADMIN’)) { die(‘direct access not permitted’); }

gmap api: hide street view and hide possibility to change map type (terrain to satelite for instance)

To disable street view and possibility to change map type is pretty easy, when initializing the map, simple set the corresponding variables to false: street view: streetViewControl: false map type: mapTypeControl: false Proof below: var mapOptions = { center: new google.maps.LatLng(46, 2), zoom: 0, mapTypeId: google.maps.MapTypeId.ROADMAP, streetViewControl: false, mapTypeControl: false }; gmap = new google.maps.Map(document.getElementById(“rdw-gmap-canvas”),    mapOptions); sources http://stackoverflow.com/questions/10295838/gmap-initialize-streetview-only-without-roadmap https://developers.google.com/maps/documentation/javascript/tutorial

wp automatically escaping global vars!

This thing is incredible. Php has been telling people for ages that variables should not be automatically escaped, that it was an error to the extent they even removed this feature altogether starting from php 5.4. Guess what? WordPress has it’s own behavior to escape the global vars on its own! independently from php! And even better, they know it for more than a year and there is no native way to deactivate this! Before wp is loaded: var_dump($_GET['var']); //string ‘st laurent d” (length=13) Single quote at end of string is unescaped. After wp is loaded: var_dump($_GET['var']); //string ‘st laurent [...]

wordpress: add css file for your plugin admin page only

If you want to add a css file that is loaded only when your plugin admin page is displayed, here is how to do it: Step 1: attach to appropriate hook: add_action(‘admin_enqueue_scripts’, ‘myplugin_loadAdminCss’); Step 2: inside your hooked function, filter on provided parameter: function myplugin_loadAdminCss($hook) {         if ((‘plugins_page_XXX’) != $hook) { return; } wp_register_style(‘myplugin_admin_css’, plugins_url(‘/css/admin.css’, __FILE__), false, ’1.0.0); } Key here is to filter on value provided to your function (named $hook here). This value corresponds to the admin page being currently displayed, with a special value when this page is the “plugins.php” page where $hook is ‘plugins_page_XXX’ [...]

jquery plugins: popup message

Here are some great jquery plugins for showing up popup messages: http://akquinet.github.com/jquery-toastmessage-plugin/ http://needim.github.com/noty/  

resize multiple images using shell

Good news for linux users, bulk resizing pictures is extremely easy thanks to imagemagick. Here are the steps to follow: install imagemagick – for debian/ubuntu: sudo apt-get install imagemagick go to your folder: cd <path_to_my_folder> reisze your pictures: for file in *.jpg; do convert $file -resize 1024×1024 -quality 90 resized_$file; done that’s it! once process is finished, you will see all resized files: ls resized_*.jpg This is very useful to minimize space used on cloud storage (ex: picasa, googledrive, …), speed up upload of pictures and number of pictures that can be stored! Even better: imagemagick keeps ratio when resizing [...]

ubuntu 12.10: remote desktop is not refreshing [solved]

When connecting to another computer using remote desktop or another vnc client (such as vncviewer available in xvnc4viewer package), initial screen is the remote computer screen but after that there is no screen refresh. Mouse is moving but screen is not refreshing. Apparently this is caused by the nice visual effects of new ubuntu interface. Solution Disable these effects. Ask remote user to do the following: logout In login screen, ensure username is selected/active Right next to username, click on icon Select “Gnome (no effects”) Enter password to log into the computer That’s it. Connect with vnc and everything should [...]

explode and merge pdf files in linux

If you are interested in merging multiple pdf files together, extracting single pdf pages from a larger document or reorder a pages, “pdftk” makes the life pretty easy! Simply install it (“sudo apt-get install pdftk” in ubuntu/debian based distros) and then use it as follows: to explode one big pdf into unitary pages: pdftk <path_to_pdf_file> burst This will generate pg_00n.pdf single files in current directory from which command line is being executed. to merge multiple pdf files together: put them all into a given folder and run: pdftk <path_to_pdfs>/*.pdf cat output output.pdf sources http://www.linuxscrew.com/2010/06/18/the-easiest-way-to-split-and-merge-pdf-files-in-ubuntu/ http://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/

google script equivalent of xlDown, xlRight

I recently started creating scripts for google spreadsheet documents, the javascript based scripts. Unfortunately, I could not find the equivalent of xls vba range(“A1″).end(xlDown) in native google script functions. As such I created a working js equivalent. Only issue with it is performance. It is not really fast, but this is more due to Apps Script rather than the code itself or the fact that it is written in js. In case someone find a native equivalent to this function, please do not hesitate to share. /** * V0.2 => PERF IMPROVED * * Home-made equivalent of xls range().end(xlToRight) function [...]