Posts

Showing posts with the label path

How to set name of the wxr file when exporting blog data using wp-cli

By default (actually, you cannot change right now), when you export blog data usingWP-CLI, the wxr will be name as following: myblogname.wordpress.2015.xml 1. Clone the wp-cli project: $ git clone https://github.com/wp-cli/wp-cli.git 2. Install composer and install WP-CLI's dependencies: $ curl -sS https://getcomposer.org/installer | php $ sudo mv composer.phar /usr/local/bin/composer $ cd /path/to/wp-cli/src/ $ composer install 3. Modify the get_filename_template function in /path-to-wp-cli-src/php/commands/export.php. For example, I want to name the exporting file after the blog's path: blog-1-path.xml $ nano /path/to/wp-cli/src/php/commands/export.php ... private static function get_filename_template() { $export_file_name = get_bloginfo('url') . ".xml"; $export_file_name = str_replace("http://", "", $export_file_name); $export_file_name = str_replace("/", "", $export_file_name); if( i...

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 note on HttpResponseRedirect with pagination in Django

When redirect a user after she submits data in the Django view by returning a HttpResponseRedirect object, I always use request.path as the destination. return HttpResponseRedirect(request.path) The problem is request.path returns the full path to the requested page, but not including the parameters (and the domain), so it will be annoying if I employ a pagination mechanism for the view. For example, if the user is on page 2 and submit data: http://mydomain.com/ myview/?page=2 print request.path /myview/ So the user will be always redirected back to the first page. In this case, if I want to redirect the user to the page before she submits data, I need to use this as the destination instead: request.get_full_path() request.get_full_path() will return the full path (exclude the domain) along with the parameters (page=): print request.get_full_path() /myview/?page=2 Another note is that you must call get_full_path with a parentheses: ... return HttpResponseRedi...

Wordpress Multisite - Using a custom domain for a blog

In Wordpress Multisite, when you create a blog (site), the blog's url will be something like: http://my.domain.com/mysite1 and another blog: http://my.domain.com/mysite2 What if you want to use my.awesome.domain for mysite1 ? 1. Point my.awesome.domain to the IP address of your blog server 2. Login to MySQL database of your blog, change the domain & path fields of the mysite1 blog to " my.awesome.domain " and path to "/" (table wp_blogs ) * Get blog_id of mysite1 (the latest one) SELECT * FROM table ORDER BY id DESC LIMIT 1; * Update domain & path fields of mysite1: UPDATE wp_blogs SET domain='my.awesome.domain', path='/' WHERE blog_id = <get from above query>; Now, you can access your new blog mysite1 using this url: http://my.awesome.domain References: http://codex.wordpress.org/Database_Description#Multisite_Table_Overview

Python - Rename files in batch

I have a directory which contains a lot of photos. But, for some reasons, the files's names do not have file extension. Something like: myphotos/ -------------photo1 -------------photo2 -------------photo3 ... -------------photo70 Because of that, I cannot upload those photos to facebook. The file-chooser window does not recognize them as images. So, I have to add .JPEG extension for all photos. Python helps me this time (and so many other times). Run this python script inside the myphotos directory; #! /usr/bin/python from os import listdir, rename from os.path import isfile, join def get_files_list(path): return [ f for f in listdir(path) if (isfile(join(path,f)))] def add_ext_batch(files_list): for fn in files_list:          tem_fn = fn + '.JPEG' rename(fn, tem_fn) if __name__=="__main__":        file_list = get_files_list('.')        add_ext_batch(file_list)

Ubuntu - How to add a dir to PATH

In Ubuntu 12.04 or newer, edit the ~/.bashrc to add a directory to PATH. Add the following line to the end of the file: export PATH=/my/path:$PATH For the changes to take effect: $ source ~/.bashrc

edX-platform - Remove the error phantomjs is not found.

You will see a blue warning message when starting the LMS or CMS: " p hantomjs not found on path. Set $PHANTOMJS_PATH. Using browser for jasmine tests " It's not something fatal, but I want to get rid of it :D Here is how i did it: 1. Inside the VirtualMachine (vagrant ssh), cd to /opt/edx/edx-platform/node_modules/ and install phantomjs : sudo npm install phantomjs -g phantomjs will be installed inside the node_modules dir. Change permission for the phantomjs dir: sudo chmod 755 phantomjs 2. Include the phantomjs path to your PATH: add this line to the end of ~/.bashrc : export PATH=$PATH:/opt/edx/edx-platform/node_modules/phantomjs/bin eval "$(rbenv init -)" And no more warning / error about phantomjs. Updates July 24, 2013: Pull the latest source code from master and you only need to install the phantomjs, and everything will just be fine: `sudo npm install phantomjs -g `.

Python - print the absolute path of the current file

This is just a small note when I tried to get the path of the current (python) file: #! /usr/bin python import os print os.path.dirname(os.path.abspath(__file__)) Note: The above script wont work in the Python REPL shell.