Skip to content

Instantly share code, notes, and snippets.

Avatar

Justin Bull jabes

View GitHub Profile
@jabes
jabes / binary_tree_problem.js
Created Nov 8, 2019
Count Visible Nodes in Binary Tree
View binary_tree_problem.js
// Question: In a binary tree, if in the path from root to the node A, there is no node with greater value than A’s, this node A is visible.
// We need to count the number of visible nodes in a binary tree.
// For example, in the following tree:
//
// 5
// / \
// 3 10
// / \ /
// 20 21 1
//
@jabes
jabes / wp_functions.php
Last active Mar 13, 2019
Some commonly used functions in WordPress theme development.
View wp_functions.php
<?php
if (!defined('ABSPATH')) exit("Direct access not permitted.");
define('APP_NAME', 'Viral Startup');
define('APP_SLUG', 'viral-startup');
define('APP_VERSION', SCRIPT_DEBUG ? uniqid() : 1);
define('ASSETS_PATH', get_template_directory() . '/assets/dist');
define('ASSETS_URI', get_template_directory_uri() . '/assets/dist');
@jabes
jabes / functions.sh
Last active Feb 9, 2021
Some Bash Functions
View functions.sh
#!/bin/bash
function get_rand {
echo "$(date +%s)"
}
function is_empty {
if [[ -z "$1" ]]; then echo 1; else echo 0; fi
}
@jabes
jabes / get-supported-css-event-name.js
Last active Sep 24, 2015
Get a vendor prefixed event name based on browser support
View get-supported-css-event-name.js
// http://stackoverflow.com/a/1026087
function capitalizeFirstLetter(string) {
return (typeof string === 'string' || string instanceof String) ?
string.charAt(0).toUpperCase() + string.slice(1) :
false;
}
/**
* Enum for css event group values.
* @readonly
View .gitconfig
[alias]
l = log --pretty=format:\"%C(yellow)%h %ad%Cred%d %Creset%s%Cblue [%cn]\" --decorate --date=iso
la = "!git l --author=\"$(git config user.name)\""
s = status --short
a = add
aa = add --all
ac = !git add . && git commit --all --message
b = branch
c = commit --verbose
cm = commit --verbose --message
@jabes
jabes / facebook-spinner.css
Last active Aug 29, 2015
Sass + Compass Facebook spinner
View facebook-spinner.css
.facebook-spinner {
@include facebook-spinner;
}
@jabes
jabes / relative_date.php
Last active Sep 4, 2020
PHP Relative Date
View relative_date.php
# Copyright (c) 2020 Justin Bull
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
@jabes
jabes / message.html
Created Sep 27, 2014
Message Bubbles
View message.html
<div class="message orient-left theme-blue">
<div class="message-inner">
<div class="message-body">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus pulvinar sodales ipsum, sit amet ultricies sem ultrices ut. Fusce lorem.</div>
</div>
</div>
<div class="message orient-right theme-gray">
<div class="message-inner">
<div class="message-body">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus pulvinar sodales ipsum, sit amet ultricies sem ultrices ut. Fusce lorem.</div>
</div>
</div>
@jabes
jabes / google_address_auto_complete
Created Feb 3, 2014
Populate a form input using Twitter Bootstrap's typeahead and the Google places autocomplete service
View google_address_auto_complete
function getAddressComponents(address_components) {
var result = {},
allowable_types = ['country', 'locality', 'postal_code', 'route', 'street_number', 'administrative_area_level_1'],
type_aliases = {
administrative_area_level_1: "region"
};
$.each(address_components, function (index, value) {
var type = value.types[0];
if (allowable_types.indexOf(type) >= 0) {
if (type_aliases.hasOwnProperty(type)) {
@jabes
jabes / static_google_map
Last active Dec 13, 2015
This method provides a simple solution to creating static google maps. It can generate a map url with as little information as the address, but you can also extend the default parameters if needed.
View static_google_map
function convert_color(&$color) {
if (strpos($color, "0x")) return;
$color = ltrim($color, "#");
if (ctype_xdigit($color)) $color = "0x" . $color; // is the color value a hexadecimal digit?
}
function static_google_map($mapAddress = null, $customParams = array(), $output = true) {
$delimiter = "&amp;";
$pipe = "%7C";
$maxDimension = 640;
$apiPath = 'http://maps.googleapis.com/maps/api/staticmap';