Skip to content

Instantly share code, notes, and snippets.

View Darkflib's full-sized avatar
🏠
The real problem is not whether machines think, but whether men do.

Mike Preston Darkflib

🏠
The real problem is not whether machines think, but whether men do.
View GitHub Profile
@Darkflib
Darkflib / subscribe.php
Created December 16, 2011 09:07
redis subscribe in php
<?php
//just making a note of this here for later use...
//subscribe.php
function f($redis, $chan, $msg) {
switch($chan) {
case 'chan-1':
print "get $msg from $chan\n";
break;
case 'chan-2':
@Darkflib
Darkflib / gist:1487788
Created December 16, 2011 20:20
plugins in php
<?php
print_r($_SERVER);
define('PLUGINDIR','./plugin.d/');
foreach (glob(PLUGINDIR."*.php") as $filename) {
require_once($filename);
$basename=substr($filename,strlen(PLUGINDIR),-4);
$funcname='plugin_'.$basename;
$result[$basename]=$funcname();
}
@Darkflib
Darkflib / gist:1490701
Created December 17, 2011 16:53
Task Queues in redis
Rough concept is as follows.
Setup 4 lists for each queue.
for a queue 'foobar'
'queue:foobar:low'
'queue:foobar:medium'
'queue:foobar:high'
'queue:foobar:run_at'
and optionally 'queue:foobar:failed'
@Darkflib
Darkflib / gist:1884523
Created February 22, 2012 12:03
Setting up ssh keys
<h3>Generating the keys</h3>
<p>Generating the key isn't difficult.</p>
<code>
[root@server1 ~]# <b>ssh-keygen</b>
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): <b>test_key</b>
Enter passphrase (empty for no passphrase): <b>my passphrase</b>
Enter same passphrase again:<b>my passphrase</b>
@Darkflib
Darkflib / gist:1884880
Created February 22, 2012 12:42
Generating RSS 2.0 with SimpleXML in PHP
<?php
$link=mysql_pconnect($db['write']['host'],$db['write']['user'],$db['write']['pass']) or die ("Could not connect to datadase");
mysql_select_db($db['write']['name']) or die ("could not select database");
//patharray is an essentially an exploded $_SERVER['REQUEST_URI']
//for articles rss feeds it would be /rss/articles/categoryname
//so $patharray[0]='rss', $patharray[1]='articles' and $patharray[2]='categoryname'
const('SITENAME','Example.com');
const('WEBMASTER','test@example.com (test@example.com)');
@Darkflib
Darkflib / gist:1884948
Created February 22, 2012 12:48
Sitemaps in SimpleXML in PHP
<?php
header('Content-type: text/xml');
//connect to db
$link=mysql_pconnect($db['write']['host'],$db['write']['user'],$db['write']['pass']) or die ("Could not connect to datadase");
mysql_select_db($db['write']['name']) or die ("could not select database");
$base='http://'.$_SERVER['HTTP_HOST'];
$xml = new SimpleXMLElement("<?xml version='1.0' encoding='UTF-8' ?>\n".'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" />');
@Darkflib
Darkflib / example output
Created October 2, 2012 07:15
GeoIP example.
teamplayr.com:
This host is located in: NA
This host is located in: US
Array
(
[continent_code] => NA
[country_code] => US
[country_code3] => USA
[country_name] => United States
[region] => TX
@Darkflib
Darkflib / twitstream.php
Created October 2, 2012 07:20
Twitter to syslog streamer
<?php
/*
This has been used for testing a logstash install and searching infrastructure. It is a quick and dirty implementation of the twitter streaming api. A better way would be to do it with curl with callback handlers. Normal curl wont work as the stream doesn't have a proper end.
*/
set_time_limit(0);
$query_data = array('track' => '#devops', 'stall_warnings' => 'true');
$user = 'twitteraccount'; // replace with your account
@Darkflib
Darkflib / geoip-package.sh
Created October 7, 2012 20:32
Packaging GeoIP
#!/bin/bash
#### Edit the paths to suit your environment.
mkdir /tmp/geoip
cd /tmp/geoip/
rm -f *.dat
wget -N -q http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
gzip -d - < GeoIP.dat.gz > GeoIP.dat
@Darkflib
Darkflib / Makefile
Last active December 11, 2015 19:48
requires fpm (with rubygems installed: gem install fpm) Example packaging with fpm (https://github.com/jordansissel/fpm)
NAME=kibana
VERSION=0.1.5
MAINTAINER="Mike Preston <mike@sysdom.com>"
URL="https://domain.com/mikepreston/kibana-packaging"
DOWNLOADURL="https://github.com/rashidkpc/Kibana/tarball/v0.1.5"
.PHONY: package
package:
#rm -f $(NAME)-*.tgz
wget -O $(NAME)-$(VERSION).tgz -N https://github.com/rashidkpc/Kibana/tarball/v0.1.5