Skip to content

Instantly share code, notes, and snippets.

View kodie's full-sized avatar
💻
#doworkson

Kodie Grantham kodie

💻
#doworkson
View GitHub Profile
@kodie
kodie / 38835949-sample.js
Created August 10, 2016 16:50 — forked from akanix42/38835949-sample.js
There are a variety of ways to do that; I'd recommend using "classes" (prototypal inheritance) as I think it enhances readability. This sample assumes you are using a version of Meteor new enough to use the ecmascript package (you can do it without ecmascript, it's just not as readable). I'm going to write the example for Meteor 1.3+.
/**
* First, add `api.use('ecmascript');` to your package.js files.
* packages/project:modules-core/package.js:
**/
Package.describe({
name: 'project:modules-core',
summary: 'Core package for Modules.',
version: '1.0.0'
});
@kodie
kodie / arraySearch.sh
Created August 25, 2016 16:18
Searches array for a string and returns it's position/key if found.
function arraySearch {
local i
local output
local a=("$@")
local last_idx=$((${#a[@]} - 1))
local b=${a[last_idx]}
unset a[last_idx]
for i in "${!a[@]}" ; do
if [ "${a[$i]}" == "$b" ]; then
@kodie
kodie / txtStyle.sh
Created August 25, 2016 16:51
Functions to display styled text
function txtStyle {
local color
local background
local style
local output
case "$1" in
"black") color="30" ;;
"red") color="31" ;;
"green") color="32" ;;
@kodie
kodie / csv_to_array.php
Last active September 16, 2016 14:51
Pulls .CSV file contents into an associative array.
<?php
function csv_to_array($file, $line_length="0", $delimiter=",", $enclosure="\"", $escape="\\") {
$csv = array();
$keys = array();
$row = 0;
if (($handle = fopen($file, "r")) !== FALSE) {
while (($data = fgetcsv($handle, $line_length, $delimiter, $enclosure, $escape)) !== FALSE) {
$num = count($data);
for ($c=0; $c < $num; $c++) {
if ($row == 0) {
@kodie
kodie / untitled
Last active December 15, 2016 18:39
Find PHP Short Tags
<\?(?!php)(?!xml)(?!=)
@kodie
kodie / change_url_param.php
Last active June 20, 2017 19:14
Add, change or remove a parameter from a URL.
<?php
function change_url_param($params = null, $url = null) {
if (!$url) { $url = '//' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; }
$p = parse_url($url);
if (isset($p['scheme'])) { $s = $p['scheme'] . '://'; } else { $s = '//'; }
if (substr($url, 0, 2) == '//') { $s = '//'; }
if (isset($p['host'])) { $h = $p['host']; } else { $h = ''; }
if (isset($p['path'])) { $t = $p['path']; } else { $t = '/'; }
if (isset($p['query'])) { parse_str($p['query'], $q); } else { $q = array(); }
if (isset($p['fragment'])) { $f = '#' . $p['fragment']; } else { $f = ''; }
@kodie
kodie / matches.js
Created July 24, 2017 17:20
A recursive, case-insensitive, keyword matcher.
function matches(str, kw) {
var m = [];
if (kw.constructor !== Array) { kw = [kw]; }
for (var i = 0; i < kw.length; i++) {
var f = str.match(new RegExp(kw[i], 'gi'));
if (f) { m = m.concat(f); }
}
return m;
@kodie
kodie / roshHashanah.js
Created July 27, 2017 21:36
Calculate when Rosh Hashanah is
var roshHashanah = function(y) {
var g = (y % 19) + 1
var n = (Math.floor(y / 100) - Math.floor(y / 400) - 2) + ((765433 / 492480 * ((12 * g) % 19)) + ((y % 4) / 4) - ((313 * y + 89081) / 98496));
var r = Math.floor(n);
var m = 9;
var h = m;
var d = r;
if (r > 30) { h = 10; d = r - 30; }
var a = Math.floor((14 - h) / 12);
var i = y - a;
@kodie
kodie / convertHebrewDate.js
Last active July 27, 2017 22:07
Convert hebrew dates
/*!
Original code found here: http://www.dafaweek.com/HebCal/HebCalSampleSource.php
Simplifed by Kodie Grantham - http://kodieg.com
Hebrew Months:
1 - Tishrei
2 - Cheshvan
3 - Kislev
4 - Teves
5 - Shevat
<?php
function base64_upload($base64, $filename = null) {
if (!$filename) $filename = md5($base64);
if (!pathinfo($filename, PATHINFO_EXTENSION)) $filename .= '.jpg';
$content = base64_decode($base64);
$upload_dir = wp_upload_dir();
$file = $upload_dir['path'] . DIRECTORY_SEPARATOR . $filename;
file_put_contents($file, $content);