Skip to content

Instantly share code, notes, and snippets.

View Alanaktion's full-sized avatar
:shipit:
Working on too many things.

Alan Hardman Alanaktion

:shipit:
Working on too many things.
View GitHub Profile
@Alanaktion
Alanaktion / turtles.php
Last active August 29, 2015 14:06
Finds a list of all images from xkcd 1416
<?php
/**
* turtles.php
*
* Uses the c.xkcd.com API to get a list of all images within xkcd #1416 Pixels
*
* @author Alan Hardman <alan@phpizza.com>
*/
/**
<?php
if(!empty($_GET["host"])) {
$host=$_GET["host"];
if(strpos($host,"/")!==false && ($h=parse_url($host,PHP_URL_HOST))!==false)
$host=$h;
$host=preg_replace("/(^\-)?[^0-9a-z\.]/i","",$host);
$result=shell_exec("ping -nc 1 -W 2000 $host");
preg_match("/(?<=time=)[0-9\.]+/",$result,$m);
if(!empty($m[0]))
$out=array("online"=>true,"host"=>$host,"ping"=>$m[0]."ms");
@Alanaktion
Alanaktion / ghost2jekyll.php
Created October 31, 2014 03:03
Ghost to Jekyll with PHP
#!/usr/bin/php
<?php
if (empty($argv[1])) {
die("Filename parameter is required." . PHP_EOL . "Example: ./ghost2jekyll.php GhostData.json" . PHP_EOL);
}
@mkdir("_drafts");
@mkdir("_posts");
@Alanaktion
Alanaktion / mysqldumpsplitter.sh
Created November 14, 2014 20:44
Split mysqldump files by table
#!/bin/sh
# http://kedar.nitty-witty.com
#SPLIT DUMP FILE INTO INDIVIDUAL TABLE DUMPS
# Text color variables
txtund=$(tput sgr 0 1) # Underline
txtbld=$(tput bold) # Bold
txtred=$(tput setaf 1) # Red
txtgrn=$(tput setaf 2) # Green
txtylw=$(tput setaf 3) # Yellow
txtblu=$(tput setaf 4) # Blue
@Alanaktion
Alanaktion / gist:c00e13a2de0729ce63fc
Created November 28, 2014 22:00
Tiny PHP slugify function
<?php
function slugify($str) {
return trim(strtolower(preg_replace("/-+/", "-", preg_replace("/[^a-z0-9]/i", "-", $str))), "-");
}
@Alanaktion
Alanaktion / collatz.php
Last active August 29, 2015 14:11
Collatz conjecture test
<?php
/**
* Collatz Conjecture Test
*
* This will generate a file showing each step taken to reach 1 following
* the Collatz Conjecture with integers between 2 and 2^20. Note that the
* resulting file will be over 2 GB, so changing pow(2, 20) to a smaller
* number like pow(2, 16) may be preferable.
*
* @author Alan Hardman <alan@phpizza.com>
@Alanaktion
Alanaktion / autosetup.sh
Last active August 29, 2015 14:15
Auto-setup an Ubuntu machine
#!/bin/bash
# Sets up a new Ubuntu installation with good things
# Desktop and Server are supported
# Detect Ubuntu version
distro="server"
(dpkg -s "ubuntu-desktop" && distro="ubuntu") > /dev/null 2>&1
(dpkg -s "xubuntu-desktop" && distro="xubuntu") > /dev/null 2>&1
(dpkg -s "kubuntu-desktop" && distro="kubuntu") > /dev/null 2>&1
### Keybase proof
I hereby claim:
* I am alanaktion on github.
* I am alanaktion (https://keybase.io/alanaktion) on keybase.
* I have a public key whose fingerprint is F7D8 B00D 7324 35F9 42A9 352E 27A7 9A65 774B 4AF0
To claim this, I am signing this object:
@Alanaktion
Alanaktion / .bashrc
Last active August 29, 2015 14:26
Bash startup script
# Bash settings for ultimate happiness
# Cross-platform and full of hax
# ls aliases
alias ls='ls --color'
alias ll='ls -alhF'
alias la='ls -A'
alias l='ls -CF'
# Shortcuts
@Alanaktion
Alanaktion / setup-osx.sh
Created October 7, 2015 20:08
Auto-setup for OS X
#!/bin/bash
# Sets up a new OS X installation with reasonable defaults
# Based partially on https://gist.github.com/saetia/1623487
echo 'Setting defaults...'
# Use plain text mode for new TextEdit documents
defaults write com.apple.TextEdit RichText -int 0
# Set default Finder location to home folder (~/)