Posts

Showing posts with the label function

How to fix "Uncaught TypeError: $(…).owlCarousel is not a function" err

Ok, jQuery included, Owl Carousel included, checked checked checked, still doesn't work. The error kept showing up: Uncaught TypeError: $(…).owlCarousel is not a function What the hell is going on? Then I realized that the jQuery library was included twice by some of the plugins. So I'm using this following technique to get rid of the error: (function($) { $(document).ready(function(){ $("#owl-demo").owlCarousel({ ...  }); }); }) (jQuery);

Django ImageField rename file on upload

By default Django keeps the original name of the uploaded file but more than likely you will want to rename it to something else (like the object's id). Luckily, with ImageField or FileField of Django forms, you can assign a callable function to the upload_to parameter to do the renaming. For example: from django.db import models from django.utils import timezone import os from uuid import uuid4 def path_and_rename (instance, filename):     upload_to = 'photos'     ext = filename.split('.')[-1]     # get filename     if instance.pk:         filename = '{}.{}'.format(instance.pk, ext)     else:         # set filename as random string         filename = '{}.{}'.format(uuid4().hex, ext)     # return the whole path to the file     return os.path.join(upload_to, filename) class CardInfo (models.Model):     id_number = models.CharFie...

Multilevel drop-down menu in WordPress with Bootstrap 3

To integrate Bootstrap 3 navigation menu to WordPress you can use the following walker class: https://github.com/twittem/wp-bootstrap-navwalker But, the problem is it only allows a single dropdown level to honer BootStrap 3's mobile first philosophy. Fortunately, the guy this blog post had done a little hack to bootstrap and the walker class above to support multilevel drop-down menu: Blog post: http://www.jeffmould.com/2014/01/09/responsive-multi-level-bootstrap-menu/ Github repo: https://github.com/jeffmould/multi-level-bootstrap-menu Basically, what you should do to have a bootstrap 3 style dropdown menu in your WordPress theme are: 1. Copy the  wp-bootstrap-navwalker.php file from the github repo to the theme's root directory 2. Add this style to your theme: .dropdown-submenu{position:relative;} .dropdown-submenu>.dropdown-menu{top:0;left:100%;-webkit-border-radius:0 6px 6px 6px;-moz-border-radius:0 6px 6px 6px;border-radius:0 6px 6px 6px;} .dropdo...

ExcelFu - Concatenate string with condition

How can I achieve table #2 from table #1 in Excel? TABLE1 => TABLE2  Name No. No. Name A 1 1 A,D,K B 2 2 B,G,H,I C 3 3 C,E,F D 1 E 3 F 3 G 2 H 2 I 2 K 1 There are 2 things I need to do to create table 2: 1. Filter TABLE2 by No. column 2. Concatenate those records which have the same No. But, with the built-in functions set of Excel spreadsheet, I can only do 1 thing at a time. I meant I can only concatenate string without condition or only filter records without concatenate the results. So, the only way is to create a User Define Function : 1. Press ALT+F11 in excel to open the Microsoft Visual Basic window. 2. Click Insert menu > Module and define the ConcatenateIf function: Function ConcatenateIf (CriteriaRange As Range, Condition As Variant, _         ConcatenateRange As Range, Optional Separator As String = ",") As Variant     Dim i As L...

Accept both username and email address as login identity in simplesamlphp

By default, simplesamlphp only allow you to login by username. But, you hack the source code to make simplesamlphp accept both username and email address as login identity. The solution is pretty simple: + just take the input username and check if -- it is an email than split the string, get only the username part -- it is not an email, than use the input string # nano /path/to/simplesamlphp/modules/core/www/loginuserpass.php ... function get_username($un) {         if (strpos($un,'@') !== false) {                 $un = strstr($un, '@', true);         }         return $un; } if (array_key_exists('username', $_REQUEST)) {         $username = get_username($_REQUEST['username']); } elseif ($source->getRememberUsernameEnabled() && array_key_exists($source->getAuthId() . '-username', $_COOKIE)) {         $usernam...

Javascript - Delay the execution a function

If for some reasons you want to delay the execution of a javascript function, you just need to use setTimeout, the pure built-in javascript function which is compatible with all browsers: * Function without parameters: setTimeout(function_name, 1000); * Function with parameters: setTimeout(function() { function_name(params) }, 1000);