Skip to content

Instantly share code, notes, and snippets.

@sepehr
sepehr / pgp.md
Last active Apr 8, 2021
PGP Guide
View pgp.md

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 Sep 22, 2014
Perl: Convert Apache access log to CSV
View accesslog2csv.pl
#!/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 / readable_random_string.php
Last active Mar 15, 2021
PHP: Human-readable Random String
View readable_random_string.php
<?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 Aug 16, 2012
Apache: .htaccess Template
View .htaccess
##
# 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 / 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 / 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 / uk_postcode_validator.php
Last active Oct 13, 2020
PHP: UK Postcode Validation
View uk_postcode_validator.php
/**
* Custom validation callback to validate UK postcodes.
*
* It also tries to format provided postcode in correct format.
*
* Note: It's only usable for "postcode" fields.
*/
public function check_postcode_uk($original_postcode)
{
// Set callback's custom error message (CI specific)
View greasemonkey_template.user.js
// ==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 / 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 / gitignore2svnignore.sh
Created Jun 24, 2014 — forked from iegik/gitignore2svnignore.sh
Shell: Convert .svnignore to .gitignore & viceversa
View gitignore2svnignore.sh
#!/bin/bash
cat .gitignore | sed 's/^/\.\//g;s/\(.*\)\/\([0-9a-zA-Z\*\?\.]*\)$/svn propedit svn:ignore "\2" \1 /mg' | bash