Skip to content

Instantly share code, notes, and snippets.

@sepehr
sepehr / array_map_assoc.php
Created Sep 1, 2012
PHP: Array Map Associative
View array_map_assoc.php
<?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 Sep 1, 2012
JS: Dump Helper (print_r)
View print_r.js
/**
* 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 Jan 19, 2016
Sublime Settings
View Default(OSX).txt
[
{ "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 Nov 10, 2015
SVN: Remove Deleted Files
View svn_rm_deleted.sh
svn st | grep '^!' | awk '{print $2}' | xargs svn delete --force
@sepehr
sepehr / csv_parse.php
Created Sep 12, 2012
PHP: Parse CSV into Keyed Array
View csv_parse.php
<?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 Jul 9, 2018
PHP: Recursive directory removal
View rmdir_recursive.php
<?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 Jan 19, 2016
LCDHype script for Asus G50/G70 LCDs.
View lcdhype-asus-g50-g70.txt
#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
PHP: Get month difference between two timestamps
View get_month_diff.php
<?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 Aug 27, 2013
PHP: Case-insensitive in_array()
View in_arrayi.php
<?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 Aug 27, 2013
PHP: truncate()
View truncate.php
<?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.
*
You can’t perform that action at this time.