Skip to content

Instantly share code, notes, and snippets.

View ain's full-sized avatar

Ain Tohvri ain

View GitHub Profile
@ain
ain / uniqid.js
Created May 23, 2013 19:57
JavaScript alternative of PHP uniqid()
function uniqid (prefix, more_entropy) {
// + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + revised by: Kankrelune (http://www.webfaktory.info/)
// % note 1: Uses an internal counter (in php_js global) to avoid collision
// * example 1: uniqid();
// * returns 1: 'a30285b160c14'
// * example 2: uniqid('foo');
// * returns 2: 'fooa30285b1cd361'
// * example 3: uniqid('bar', true);
// * returns 3: 'bara20285b23dfd1.31879087'
@ain
ain / gdpr_countries.vcl
Created July 19, 2022 17:46
VCL dictionary for GDPR-regulated EU countries (ISO 3166-1 Alpha-2)
table gdpr_countries {
"AT": "Austria",
"BE": "Belgium",
"BG": "Bulgaria",
"HR": "Croatia",
"CY": "Republic of Cyprus",
"CZ": "Czech Republic",
"DK": "Denmark",
"EE": "Estonia",
"FI": "Finland",
@ain
ain / log.php
Created February 23, 2012 19:47
tail functionality in PHP
<?php
// full path to text file
define("TEXT_FILE", "/home/www/default-error.log");
// number of lines to read from the end of file
define("LINES_COUNT", 10);
function read_file($file, $lines) {
//global $fsize;
@ain
ain / free-memory.rb
Last active December 19, 2020 22:20 — forked from vigo/free-memory.rb
#!/usr/bin/env ruby
# encoding: utf-8
# By Uğur Özyılmazel, @vigobronx | @ugurozyilmazel
# http://vigodome.com | http://ugur.ozyilmazel.com | http://github.com/vigo
def get_paged_memory_usage(match_string, paging=4096)
mvar = 3
if match_string.split(/[^\w]/).length > 1
mvar = 4
@ain
ain / Array.prototype.compare.js
Last active September 25, 2020 07:17
JavaScript compare() method for Array
Array.prototype.compare = function(array) {
if (!array) {
return false;
}
if (this.length !== array.length) {
return false;
}
for (var i = 0, l = this.length; i < l; i++) {
if (this[i] instanceof Array && array[i] instanceof Array) {
if (!this[i].compare(array[i])) {
@ain
ain / hotfix.sh
Created November 19, 2018 21:00
Check last commit message for [hotfix]
#/bin/bash
if [[ `git log -1 --pretty=%B` == *"[hotfix]"* ]]; then
echo "HOTFIX!"
else
echo "NOT HOTFIX!"
fi
@ain
ain / wp-importer.rb
Created July 17, 2016 22:44
Wordpress data Import script for Jekyll 3
require "jekyll-import"
JekyllImport::Importers::WordpressDotCom.run({
"source" => "wp-export.xml"
})
@ain
ain / release-cleanup.sh
Created December 5, 2013 15:18
Release folder cleanup script for Capistrano-like folder structure
#!/bin/bash
KEPT_RELEASES=5
CWD=/Users/ain/temp
# Check for Bash config
# On FreeBSD/OS X GNU ls is required for -v option
if [ -f ~/.bashrc ]; then
shopt -s expand_aliases
source ~/.bashrc
@ain
ain / email-regex.js
Last active December 28, 2015 23:19
Email validation regex for emails likely to be used in Germany.
var emailRegex = /^([\wäöüÜÖÄß])+(([\.]{0,1}[\wäöüÜÖÄß])?)*(([\+]{0,1}[\wäöüÜÖÄß])?)*([\wäöüÜÖÄß-])*\@([\wäöüÜÖÄß-]+\.)+([\w]{2,})+$/;
@ain
ain / Keyboard-et.plist.part
Last active December 26, 2015 15:08
Mapping for PressAndHold.app for selecting special characters on press and hold Q key on Mac.
<key>Roman-Accent-Q</key>
<dict>
<key>Direction</key>
<string>right</string>
<key>Keycaps</key>
<string>` ^ ° • ★ “ ”</string>
<key>Strings</key>
<string>` ^ ° • ★ “ ”</string>
</dict>