Skip to content

Instantly share code, notes, and snippets.

@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 / greasemonkey_template.user.js
Created August 18, 2012 17:34
Userscript Template
// ==UserScript==
// @name SCRIPT
// @description SCRIPT DESCRIPTION
// @icon https://raw.github.com/sepehr/userscript-SCRIPT/master/SCRIPT.png
//
// @author Sepehr Lajevardi <me@sepehr.ws>
// @namespace http://github.com/sepehr
// @downloadURL https://raw.github.com/sepehr/userscript-SCRIPT/master/SCRIPT.user.js
//
// @license GPLv3 - http://www.gnu.org/licenses/gpl-3.0.txt
@sepehr
sepehr / readable_random_string.php
Last active December 8, 2023 15:11
PHP: Human-readable Random String
<?php
/**
* Generates human-readable string.
*
* @param string $length Desired length of random string.
*
* retuen string Random string.
*/
function readable_random_string($length = 6)
@sepehr
sepehr / .htaccess
Created August 16, 2012 15:22
Apache: .htaccess Template
##
# Apache .htaccess template
##
## Protect files and directories from prying eyes.
<FilesMatch "\.(make|test|md|po|sh|.*sql|.*bson|tpl(\.php)?|svn-base)$|^(code-style\.pl|Entries.*|Repository|Root|Tag|Template|all-wcprops|entries|format)$">
Order allow,deny
</FilesMatch>
## Don't show directory listings for URLs which map to a directory.
@sepehr
sepehr / pgp.md
Last active November 18, 2023 19:11
PGP Guide

PGP Guide

GPG vs PGP

PGP can refer to two things:

The Pretty Good Privacy software originally written by Phil Zimmermann, and now owned by Symantec. The formats for keys, encrypted messages and message signatures defined by that software. These have now been formalised as the OpenPGP standard. The GPG software is an independent implementation of the OpenPGP standards, so you can use it to exchange encrypted messages with people using other OpenPGP implementations (e.g. Symantec's PGP).

@sepehr
sepehr / accesslog2csv.pl
Created September 22, 2014 08:04
Perl: Convert Apache access log to CSV
#!/usr/bin/perl
#
# @file
# Converter tool, from Apache Common Log file to CSV.
#
# All code is released under the GNU General Public License.
# See COPYRIGHT.txt and LICENSE.txt.
#
@sepehr
sepehr / ubuntu-web.md
Last active August 23, 2023 04:28
Webserver recipe for Ubuntu 14.04

Webserver setup recipe for Ubuntu 14.04 LTS

A few notes:

  • All commands should be run as root unless specified otherwise.
  • Commands that sould be run locally have a local$ prefix.

Initial setup

Hostname

@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.
*/

$2a$11$E8FlUtDWGIfWWinkWS9c7uXbWa.fINB/55ZuPtb.ed/CivkX9/exa

@sepehr
sepehr / get_daterange_timestamps.php
Created August 27, 2013 09:16
PHP: Get corresponding timestamp boundaries of a daterange
<?php
/**
* Generates timestamp bounderies for the passed date range name.
*
* @param string $range Date range name.
*
* @return array
*/
function get_daterange_timestamps($range)