Skip to content

Instantly share code, notes, and snippets.

View elchappo's full-sized avatar
👻

Pawel Zareba elchappo

👻
View GitHub Profile
@elchappo
elchappo / gist:3953057
Created October 25, 2012 14:55
htaccess php rewrite
Options +FollowSymLinks
RewriteEngine On
RewriteBase /subfolder/
RewriteCond %{REQUEST_URI} !^/subfolder
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-z]+)/$ $1.php
RewriteRule ^([a-z]+-?[a-z]+)/$ $1.php
@elchappo
elchappo / gist:3969871
Created October 28, 2012 20:53
PHP Regex checker
<?php
$string = "abcdefgh";
$regex = "/^[a-z]+$/i";
// Syntax is preg_match(regex, string, [, out_matches [, flags [, offset]]]);
if (preg_match($regex, $string)) {
printf("Pattern '%s' found in string '%s'\n", $regex, $string);
} else {
printf("No match found in string '%s'!\n", $string);
}
?>
@elchappo
elchappo / gist:4002989
Created November 2, 2012 17:37
Search nginx access log for IP and url
cat /etc/nginx/logs/access.log | awk '{print $1 " " $4 " " $5 " " $6 " " $7}' | grep 'url'
@elchappo
elchappo / gist:4072999
Created November 14, 2012 16:07
Bash script to monitor /tmp folder on the server
#!/bin/sh
tmp_usage=$(df -h /tmp/ | tail -1 | awk '{print $4}' | awk -F "%" '{print $1}')
if [ $tmp_usage -gt 90 ]; then
echo "Your /tmp folder is $tmp_usage% full, please investigate" | mail -s "TMP folder on <server-id>" zareba.pawel@gmail.com;
fi
@elchappo
elchappo / gist:4188244
Created December 2, 2012 11:10
Generating W3C valid HTML5 <time> tags in PHP
<time datetime="<?php echo date('Y-m-d\Th:m:sO', strtotime($publishedDate)); ?>" ><?php echo date('l jS F Y', strtotime($publishedDate); ?></time>
rsync -avz /path/to/local/sync/folder -e "ssh -i /path/to/ssh/key" ubuntu@ec2instance:/path/to/remote/sync/folder
@elchappo
elchappo / boc.py
Created April 30, 2013 14:06 — forked from mekza/boc.py
#!/usr/bin/python
# -*- coding:utf-8 -*-
import itertools
import requests
import json
characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
password_length = 6
gen = itertools.combinations_with_replacement(characters,password_length)
@elchappo
elchappo / gist:6114482
Created July 30, 2013 16:23
BASH: Find unique images by file name
find . -name '*.png' -exec basename {} \; | sort | uniq -u | wc -l
file_to_disk = './tmp/large_disk.vdi'
Vagrant::Config.run do |config|
config.vm.box = 'base'
config.vm.customize ['createhd', '--filename', file_to_disk, '--size', 500 * 1024]
config.vm.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', file_to_disk]
end