Skip to content

Instantly share code, notes, and snippets.

@khoand0000
khoand0000 / form-snippets.md
Last active October 7, 2015 06:48
jquery snippets
  • Send form data using ajax requests
$.post( "test.php", $( "#testform" ).serialize() )
  .done(function( data ) {})
  .fail(function(data){
      console.log(data.responseJSON);
      console.log(data.responseText);
      console.log(data.status); // status code, ex: 400
    }); 
@khoand0000
khoand0000 / widget.md
Created September 24, 2015 20:05
'the_widget' action is not working

I don't know why but 'the_widget' action in wp-includes/widget.php is not working

	do_action( 'the_widget', $widget, $instance, $args );

Problem maybe bug from wordpress or resort theme

@khoand0000
khoand0000 / theme-frameworks.md
Created September 17, 2015 19:21
wordpress's theme frameworks
@khoand0000
khoand0000 / bootstrap.md
Last active November 24, 2015 04:48
commons of bootrap. ref: http://getbootstrap.com/css/
  • classes, tags have margin-bottom: p, .form-group
p {
margin-bottom: 10px;
}
.form-group {
margin-bottom: 15px;
}
@khoand0000
khoand0000 / prepare.php
Last active August 29, 2015 14:28
Use $wpdb->prepare with parameter is array
// ref: http://wordpress.stackexchange.com/questions/110982/how-to-modify-this-wpdb-query-to-accept-an-array-of-post-statuses
// escape the values
// $filter is array of string
$filter = array_map( 'esc_sql', (array) $filter );
$filter = "'" . implode( "','", $filter ) . "'";
$rows = $wpdb->get_results(
$wpdb->prepare(
"SELECT * FROM language_table
RewriteCond   TestString  CondPattern [flags]     
  • Defines a condition under which rewriting will take place
  • backreferences: %1 to %9: groups; %0: whole matched string
  • [flags]: 'nocase|NC' (case-insensitive); 'ornext|OR'; 'novary|NV' (no vary)
RewriteRule Pattern Substitution [flags] 
@khoand0000
khoand0000 / media.css
Last active February 3, 2016 14:40
order media
/* Small devices Tablets (>=768px), ipad 1, 2, 3, air, mini = 678px */
@media (min-width: 768px) {
}
/* Extra small devices: smartphone (iphone 3,4,5: 320; iphone 6: 375; iphone 6+: 414 */
@media (max-width: 767px) {
}
/* iphone 6 plus */
@media (max-width: 414px) {
@khoand0000
khoand0000 / on-emit.md
Created August 14, 2015 20:57
Notice when using $on and $emit
function register(id, scope, success, error) 
{
  var handler = $rootScope.$on('settings:get' + id + scope.$id, success);
  scope.$on('$destroy', handler);
  // some code
  $rootScope.$emit('settings:get' + id + scope.$id, settings);
}
  • side effect if missing + id + scope.$id is that 2 controllers call register(id, $scope, success, error), when $emit occurs, it notify 2 controllers
@khoand0000
khoand0000 / ng-show.md
Created August 14, 2015 18:01
Put ng-hide into class when using ng-show

In iOS, elements use ng-show always show when loaded and disappear immediately. To avoid the problem, add ng-hide into class like that

<a class="ng-hide" ng-show="false">some text</a>
@khoand0000
khoand0000 / cli.md
Created August 5, 2015 17:19
common ionic cli
  • emulate
ionic emulate ios -l -c -s --debug
  • upload
ionic upload