Skip to content

Instantly share code, notes, and snippets.

@x1024
x1024 / woman.sh
Created November 8, 2016 12:33
"woman" shell command
function woman() {
if [ $# -eq 0 ]; then
man
else
man $1 | head -n `expr \`man $1 | wc -l\` \* 77 / 100 ` | $PAGER
fi
}
@x1024
x1024 / notifier.py
Created July 8, 2016 16:00
slack notifications when a line is added to a logfiel
#!/usr/bin/env python2.7
from slacker import Slacker # https://github.com/os/slacker
slack = Slacker('SLACK API TOKEN HERE')
while True:
line = raw_input()
msg = 'A line was posted: %s' % line
print msg
slack.chat.post_message('@slackbot', msg)
@x1024
x1024 / gist:3a7fcc13300116c35583
Created November 9, 2014 21:26
WP Grandchildren
the_post();
$children = new WP_Query( array('post_type' => 'page', 'post_parent' => get_the_ID() );
$ids = array();
if ($children->have_posts()) {
while ($children->have_posts()) {
$children->the_post();
array_push($ids, get_the_id());
}
}
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root SITE_PATH_HERE;
index index.php index.html index.htm;
server_name SERVER_NAME_HERE;
client_max_body_size 10M;
@x1024
x1024 / gist:6569982
Last active December 23, 2015 02:58
Minecraft rolling backup script.
#!/bin/bash
echo "Backup perfomed at: `date +'%Y/%m/%d %H:%M'`"
echo "Backup perfomed at: `date +'%Y/%m/%d %H:%M'`" >> backups.log
# Make a backup
cp -r ~/unleashed/world ~/unleashed/backups/world_`date +%Y_%m_%d_%H_%M`
pushd ~/unleashed/backups
# Keep only the latest 50 backups
@x1024
x1024 / gist:6563378
Created September 14, 2013 16:28
Initial(and untested) version of a polyfill aiming to normalize IE10/IE11 pointer events.
//
// Sources:
//
// http://benalman.com/news/2010/03/jquery-special-events/
// http://learn.jquery.com/events/event-extensions/
// https://github.com/jquery/jquery/blob/master/src/event.js#L549
// https://github.com/jquery/jquery/blob/master/src/event.js#L694
@x1024
x1024 / gist:5892691
Last active December 19, 2015 03:49
var data = {
'bone-spear': 1,
'bolas': 4,
'bullets': 30,
'rifle': 1,
'cured-meat': 38,
'steel-sword': 1,
'torch': 5,
'laser-rifle': 1,
'energy-cell': 7,
@x1024
x1024 / letterpress.py
Created January 23, 2013 14:44
Use only after consulting your conscience.
#!/bin/env python2.7
#-*- coding:UTF-8 -*-
import sys
import collections
letters = collections.Counter(list(''.join(sys.argv[1:])))
words = [word.strip() for word in open('/usr/share/dict/words').readlines()
if word.find("'") == -1]
@x1024
x1024 / gist:989227
Created May 24, 2011 17:42
BitTorrent task solution
#include<stdio.h>
const int BOWLS = 40;
const int ORANGES = 9;
int count = 0;
// All the places in which an orange can't be placed are 1's
int used[BOWLS];
// A list of the oranges already placed.
@x1024
x1024 / gist:988699
Created May 24, 2011 13:30
BitTorrent task solution
#include<stdio.h>
#define BOWLS 40
#define ORANGES 9
int count = 0;
// All the places in which an orange can't be placed are 1's
int used[BOWLS];
// A list of the oranges already placed.