Skip to content

Instantly share code, notes, and snippets.

View timstermatic's full-sized avatar

Tim Roberts timstermatic

View GitHub Profile
function createDeck() {
var suits = ['c','s','h','d']
var values = ['A','2','3','4','5','6','7','8','9','10','j','q','k']
var deck = []
for(s in suits) {
for(v in values) {
deck.push(values[v] + suits[s])
}
}
deck.push('j1')
@timstermatic
timstermatic / sendmail-fix.sh
Created February 16, 2017 19:24 — forked from dhensby/sendmail-fix.sh
Stop sendmail delivering to localhost when email domain matches hostname, stop sendmail intercepting emails to info@ and others - CentOS, RHEL, Fedora
#!/bin/bash
##
##
## This scipt was inspired by http://serverfault.com/questions/65365/disable-local-delivery-in-sendmail/128450#128450
## It stops webservers sending mail that is addressed to the local hostname to localhost and instead looks remotely for a mail server
##
##
# Install sendmail-cf as this is required to customise the config
@timstermatic
timstermatic / sluggable
Created May 10, 2015 21:13
populate one field with a url slug based on value entered into another.
(function ( $ ) {
$.fn.slugger = function(options) {
var that = this;
var settings = $.extend({
target: null,
}, options );
if(settings.target) {
<?php echo $this->Paginator->numbers(array(
'before'=>'<ul class="pagination">',
'after'=>'</ul>',
'tag'=>'li',
'separator'=>false,
'currentClass'=>'active',
'currentTag'=>'a'
));?>
@timstermatic
timstermatic / gist:7384516
Created November 9, 2013 11:31
Rip a CD to MP3 with cdparanoia
# install cdparanoia e.g apt-get install cdparanoia
# rip tracks individually
cdparanoia -B
# convert to mp3 in a loop
for t in track{01..18}*.wav; do lame $t; done
@timstermatic
timstermatic / app.js
Last active December 21, 2015 08:39
app.js for simple MVC
// app.js for simple express mvc
var express = require('express');
var http = require('http');
var path = require('path');
var app = express();
var fs = require('fs');
var mongoose = require('mongoose');
mongoose.connect('mongodb://locahost/dbname');
@timstermatic
timstermatic / gist:6241437
Last active December 21, 2015 03:19
Send an email using SES and Node.js
// load aws sdk
var aws = require('aws-sdk');
// load aws config
aws.config.loadFromPath('config.json');
// load AWS SES
var ses = new aws.SES({apiVersion: '2010-12-01'});
// send to list
@timstermatic
timstermatic / gist:6163577
Last active July 31, 2016 12:46
Async unique validation with expressjs and mongoose
var mongoose = require('mongoose')
,Schema = mongoose.Schema
,ObjectId = Schema.ObjectId;
var userSchema = new Schema({
email: String,
password: String,
@timstermatic
timstermatic / user.js
Created May 20, 2013 17:29
Example of using bcrypt with mongoose middleware to enforce password hashing with bcrypt on save.
var mongoose = require('mongoose'),
Schema = mongoose.Schema
var bcrypt = require('bcrypt')
@timstermatic
timstermatic / HighlightExtract.php
Last active December 15, 2015 08:09
Finds an extract from a string (n) words before a matched word and highlights any occurrences
/**
* $str to search
* $query word to search for
* $words either side of first match to return
*/
function highlightedExtract($str, $query, $words) {
$pos = stripos($str,$query);
$after = substr($str,$pos,$words);
$prior = explode($after,$str);