Skip to content

Instantly share code, notes, and snippets.

@obiPlabon
obiPlabon / mpd.js
Created December 23, 2015 06:48
Matrix plus diff
function matrixPlusDiff(m) {
var d1 = d2 = 0;
for(var i = 0, l = m.length; i < l; i++){
d1 += m[i][Math.floor(l/2)];
d2 += m[Math.floor(l/2)][i];
}
console.log(d1-d2);
}
@obiPlabon
obiPlabon / mdd.js
Created December 23, 2015 06:35
Matrix diagonal difference
function matrixDiagDiff(m) {
var d1 = d2 = 0;
for(var i = 0, l = m.length; i < l; i++){
d1 += m[i][i];
d2 += m[i][l-(i+1)];
}
console.log(d1-d2);
}
@obiPlabon
obiPlabon / frontendDevlopmentBookmarks.md
Created November 6, 2015 19:47 — forked from dypsilon/frontendDevlopmentBookmarks.md
A badass list of frontend development resources I collected over time.
@obiPlabon
obiPlabon / .csscomb.json
Created November 3, 2015 18:33
CSS comb config
{
"remove-empty-rulesets": true,
"always-semicolon": true,
"color-case": "lower",
"block-indent": " ",
"color-shorthand": true,
"element-case": "lower",
"eof-newline": true,
"leading-zero": false,
"quotes": "double",
@obiPlabon
obiPlabon / wp-load-template.php
Last active October 22, 2015 19:50
Built in function and it's pretty helpful to understand WP global variable
<?php
function load_template( $_template_file, $require_once = true ) {
global $posts, $post, $wp_did_header, $wp_query, $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment, $user_ID;
if ( is_array( $wp_query->query_vars ) ) {
extract( $wp_query->query_vars, EXTR_SKIP );
}
if ( isset( $s ) ) {
$s = esc_attr( $s );
<?php
/**
* Template Name: Assets
*/
$js_dir = dirname( __FILE__ ) . '/assets/js/';
$css_dir = dirname( __FILE__ ) . '/assets/css/';
$js = $js_dir . '*.js';
$css = $css_dir . '*.css';
$register = array();
$enqueue = array();
@obiPlabon
obiPlabon / obi-nav-metabox.php
Last active October 16, 2015 17:37
Add metabox to WordPress menu editor
<?php
//add_action( 'admin_init', 'obi_add_meta_box' );
// load-nav-menus.php is the perfect hook for this metabox
// as we are only adding on nav menu page :)
add_action( 'load-nav-menus.php', 'obi_add_meta_box' );
function obi_add_meta_box() {
add_meta_box(
'obi-nav-metabox',
@obiPlabon
obiPlabon / .csscomb.json
Created July 30, 2015 10:51
css comb config file based on WordPress css standard
{
"remove-empty-rulesets": true,
"always-semicolon": true,
"color-case": "lower",
"block-indent": " ",
"color-shorthand": true,
"element-case": "lower",
"eof-newline": true,
"leading-zero": false,
"quotes": "double",
@obiPlabon
obiPlabon / customize-nav-item.php
Created July 20, 2015 09:02
Customize navigation menu title
<?php
function customize_nav_item( $title, $id ) {
if ( 'nav_menu_item' === get_post_type( $id ) ) {
$title = sprintf( '<span data-hover="%1$s">%2$s</span>',
esc_attr( $title ),
$title
);
}
return $title;
/**
* Get posts pending count as per Post Type.
* @param string $post_type
* @return integer Pending count.
*/
function project_get_pending_items( $post_type ) {
global $wpdb;
$pending_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = %s AND post_status = 'pending'", $post_type ) );
return (int) $pending_count;
}