Skip to content

Instantly share code, notes, and snippets.

View adrianpietka's full-sized avatar

Adrian Piętka adrianpietka

View GitHub Profile
@adrianpietka
adrianpietka / website-mirror
Last active August 29, 2015 14:13
Make website mirror with subpages of site using wget
#!/bin/bash
# using: mirror.sh http://examplepage.com
wget --mirror --page-requisites --no-parent --quota=0 --no-verbose --restrict-file-names=windows $1
@adrianpietka
adrianpietka / thumbs-maker
Created January 24, 2015 22:59
Generate thumbnails from a directory of images
#!/bin/bash
for img in *.jpg;
do
echo "Prcoessing image $img ..."
/usr/bin/convert -thumbnail 1750 "$img" "thumb.$img"
done
@adrianpietka
adrianpietka / backup-folders
Created January 25, 2015 00:08
Create single zip file of backup for each subdirectory in destination directory
#!/bin/bash
SourceDirectory="source/"
DestinationDirectory="../destination/"
cd $SourceDirectory
for CurrentSourceDirectory in $(find * -maxdepth 0 -type d );
do
FileName=$(basename $CurrentSourceDirectory);
@adrianpietka
adrianpietka / wikipedia-imieniny.py
Created February 1, 2015 17:50
wikipedia-imieniny
# -*- coding: utf-8 -*-
import urllib2
import pprint
from bs4 import BeautifulSoup
class Fete:
urls = {
'styczen' : 'http://pl.wikipedia.org/wiki/Imieniny_-_stycze%C5%84',
@adrianpietka
adrianpietka / seconds-to-hms-test.php
Last active December 23, 2015 23:29
Convert seconds to format: 1h 52m 16s
<?php
include 'seconds-to-hms.php';
class SecondsToHmsTest extends PHPUnit_Framework_TestCase
{
public function provider()
{
return [
[60, '', '0h1m0s'],
@adrianpietka
adrianpietka / get-all-links.php
Last active December 23, 2015 23:25
Get all links from html content using DomDocument Class
<?php
// Turn off all error reporting
error_reporting(0);
// Configuration
$user = 'your_login';
$password = 'you_password';
$host = 'imap.gmail.com';
<?php
function percent($part, $sum, $round = 0) {
return round($part / $sum * 100, $round) . '%';
}
function round_size($size, $round = 0) {
$sizes = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
for ($i = 0; $size > 1024 && $i <= 8; $i++) {
@adrianpietka
adrianpietka / port-scanner.php
Last active December 23, 2015 23:30
Simple port scanner
<?php
/**
* Scan host for open ports.
*
* @param string $host Host to scan.
* @param integer $timeout The connection timeout, in seconds.
* @return array
*/
function simple_port_scanner($host, $timeout = 1) {
<?php
// yep, it's not hard to decode
$root = realpath(dirname(__FILE__)).DIRECTORY_SEPARATOR;
$source = $root.'source-files'.DIRECTORY_SEPARATOR;
$target = $root.'target-files'.DIRECTORY_SEPARATOR;
$directory = new RecursiveDirectoryIterator($source);
$iterator = new RecursiveIteratorIterator($directory);