Skip to content

Instantly share code, notes, and snippets.

View jabes's full-sized avatar

Justin Bull jabes

View GitHub Profile
@jabes
jabes / binary_tree_problem.js
Created November 8, 2019 03:10
Count Visible Nodes in Binary Tree
// 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 / functions.sh
Last active February 9, 2021 16:06
Some Bash Functions
#!/bin/bash
function get_rand {
echo "$(date +%s)"
}
function is_empty {
if [[ -z "$1" ]]; then echo 1; else echo 0; fi
}
@jabes
jabes / relative_date.php
Last active September 4, 2020 17:56
PHP Relative Date
# 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 / wp_functions.php
Last active March 13, 2019 08:03
Some commonly used functions in WordPress theme development.
<?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 / static_google_map
Last active December 13, 2015 19:48
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.
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';
@jabes
jabes / get-supported-css-event-name.js
Last active September 24, 2015 21:17
Get a vendor prefixed event name based on browser support
// 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
@jabes
jabes / .gitconfig
Created July 8, 2015 22:03
Git Aliases
[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 August 29, 2015 14:19
Sass + Compass Facebook spinner
.facebook-spinner {
@include facebook-spinner;
}
@jabes
jabes / message.html
Created September 27, 2014 20:50
Message Bubbles
<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 February 3, 2014 19:15
Populate a form input using Twitter Bootstrap's typeahead and the Google places autocomplete service
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)) {