Skip to content

Instantly share code, notes, and snippets.

@sepehr
sepehr / array_map_assoc.php
Created September 1, 2012 02:56
PHP: Array Map Associative
<?php
/**
* Converts a linear array to its associative equivalent.
*
* @param $array
* Linear array to process.
* @param $function
* Callback name to call against each value.
*
* @return array
@sepehr
sepehr / print_r.js
Created September 1, 2012 04:14
JS: Dump Helper (print_r)
/**
* Debug helper similar to PHP's print_r().
*
* This function was inspired by the print_r function of PHP.
* This will accept some data as the argument and return a
* text that will be a more readable version of the
* array/hash/object that is given.
*
* @param data
* array, object or hash (assoc array)
@sepehr
sepehr / Default(OSX).txt
Last active January 19, 2016 03:18
Sublime Settings
[
{ "keys": ["ctrl+super+a"], "command": "alignment" },
{ "keys": ["ctrl+super+f"], "command": "reindent", "args": {"single_line": false}},
{ "keys": ["super+v"], "command": "paste_and_indent" },
{ "keys": ["super+shift+v"], "command": "paste" },
{ "keys": ["super+backspace"], "command": "run_macro_file", "args": {"file": "res://Packages/Default/Delete Line.sublime-macro"} },
]
@sepehr
sepehr / svn_rm_deleted.sh
Last active November 10, 2015 23:08
SVN: Remove Deleted Files
svn st | grep '^!' | awk '{print $2}' | xargs svn delete --force
@sepehr
sepehr / csv_parse.php
Created September 12, 2012 14:35
PHP: Parse CSV into Keyed Array
<?php
/**
* Parses CSV file into an associative array with the first row as field names.
*
* @param string $filepath Path to readable CSV file.
* @param array $options Parse options (eol, delimiter, enclosure, escape, to_object).
*
* @return array Associative array of parsed CSV file.
*/
@sepehr
sepehr / rmdir_recursive.php
Last active July 9, 2018 00:52
PHP: Recursive directory removal
<?php
/**
* Recursively removes a directory.
*
* @param string $path Directory path to remove.
* @param bool $suicide Whether to remove itself or not.
*
* @return void
*/
@sepehr
sepehr / lcdhype-asus-g50-g70.txt
Last active January 19, 2016 03:20
LCDHype script for Asus G50/G70 LCDs.
#Header
%KeyInit()
%Param.AvoidPluginCleanUp()
%Common.SetPriority(140)
%Graph.SetTextArea(0,0,255,31)
%Graph.Font('OCR-A',10,1)
%DefVar(xPos,Local=105)
%DefVar(yPos,Local=16)
%DefVar(an=0)
%DefVar(km,Global)
@sepehr
sepehr / get_month_diff.php
Last active May 4, 2020 23:59
PHP: Get month difference between two timestamps
<?php
/**
* Calculates how many months is past between two timestamps.
*
* @param int $start Start timestamp.
* @param int $end Optional end timestamp.
*
* @return int
*/
@sepehr
sepehr / in_arrayi.php
Created August 27, 2013 09:12
PHP: Case-insensitive in_array()
<?php
/**
* Case-insensitive in_array() wrapper.
*
* @param mixed $needle Value to seek.
* @param array $haystack Array to seek in.
*
* @return bool
*/
@sepehr
sepehr / truncate.php
Created August 27, 2013 09:14
PHP: truncate()
<?php
/**
* Truncates string to the specified length.
*
* @param string $string String to truncate.
* @param integer $len Desired length.
* @param boolean $wordsafe Whether to truncate on word boundries or not.
* @param boolean $dots Whether to add dots or not.
*