Skip to content

Instantly share code, notes, and snippets.

View cjwfuller's full-sized avatar

Chris Fuller cjwfuller

View GitHub Profile
@cjwfuller
cjwfuller / gist:3787d8387b9e8e588514
Created March 24, 2016 00:36
Script to get AWS EC2 spot instance pricing
'use strict';
let AWS = require('aws-sdk');
let ec2 = new AWS.EC2({
region: 'ap-southeast-2',
});
let params = {
DryRun: false,
InstanceTypes: [
mysql> select * from orders where user_id = 8;
+----+---------------------+---------------------+---------+---------------------+-----------------+-----------+---------------------+-------+---------------------+---------------------+----------+---------------------+-----------+----------------+---------------------+--------------------+-----------------+
| id | created_at | updated_at | user_id | when_projected | subscription_id | period_id | when_committed | total | shipping_list_price | is_shipping_vatable | vat_rate | total_excluding_vat | total_vat | order_state_id | shipping_address_id | billing_address_id | delivery_day_id |
+----+---------------------+---------------------+---------+---------------------+-----------------+-----------+---------------------+-------+---------------------+---------------------+----------+---------------------+-----------+----------------+---------------------+--------------------+-----------------+
| 3 | 2014-12-12 12:25:44 | 2014-12-16 12:59:0
@cjwfuller
cjwfuller / gist:8805887
Created February 4, 2014 15:32
Bubble sort in PHP
<?php
$arr = array( 5, 3, 2, 8, 4, 1 );
$arr_len = count( $arr );
$swap = TRUE;
while( $swap ) {
$swap = FALSE;
for( $i = 0; $i < $arr_len - 1; $i++ ) {
if( $arr[$i] > $arr[$i + 1] ) {
$tmp = $arr[$i];
$arr[$i] = $arr[$i + 1];
@cjwfuller
cjwfuller / budget-litecoin-miner
Created May 28, 2013 09:01
Budget Litecoin miner
Sapphire Radeon HD 6870 1024 MB Graphics Card - £80
GIGABYTE GA-K8N51PVM9-RH motherboard with AMD Athlon 64 3500+ 2.2GHz processor + 2GB RAM - £25
Corsair Builder Series CX 500 Watt ATX/EPS 80 PLUS Bronze Power Supply Unit - £46
No case, no peripherals, no screen
OS: CentOS 6.3 x86_64
Total: £151
Hash rate: Approx 300 Mhash/s
@cjwfuller
cjwfuller / gist:5524942
Last active May 17, 2016 16:44
Get external IP address in Node.js
var ipModule = (function() {
// Private stuff
var my = {};
var options = {
hostname: 'jsonip.com'
};
// Get the external IP address of this server using the JSON IP server
my.getIP = function(cb) {
@cjwfuller
cjwfuller / gist:5301489
Created April 3, 2013 14:04
php-pdo MySQL connection
<?php
try {
$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
foreach($dbh->query('SELECT * from FOO') as $row) {
print_r($row);
}
$dbh = null;
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
@cjwfuller
cjwfuller / gist:4169889
Created November 29, 2012 15:42
Logstash on Centos 6.3 (with GUI)

Logstash on Centos 6.3

Web GUI and Logstash agent on single server

Download logstash:

wget https://logstash.objects.dreamhost.com/release/logstash-1.1.5-monolithic.jar
@cjwfuller
cjwfuller / gist:4143025
Created November 25, 2012 10:32
Backup a directory with a timestamp in the directory name
cp -r dir/to/backup backup-$(date +"%Y-%m-%d-%T")
@cjwfuller
cjwfuller / gist:2953877
Created June 19, 2012 12:33
show all PHP errors
error_reporting( E_ALL );
ini_set( 'display_errors', '1' );