Skip to content

Instantly share code, notes, and snippets.

@craig552uk
craig552uk / mysql.service.ts
Last active Jun 18, 2020
MySQL Wrapper for NodeJS
View mysql.service.ts
import { Connection, createPool, createConnection, Pool } from 'mysql';
import { MYSQL_DATABASE, MYSQL_HOST, MYSQL_PASSWORD, MYSQL_PORT, MYSQL_USER } from './config.service';
import { InternalServerError } from 'http-errors';
import { LoggerService } from './logger.service';
import { isEmpty } from '../lib/utilities';
const logger = LoggerService.getInstance();
export class MySQLService {
View fuck_you.php
/**
* fUCK yOU php
*
* @craig552uk
*/
<?php
You echo to the browser, not to std out.
So I hunt for bugs in XHRs or (here or (there about))
@craig552uk
craig552uk / promise_chains.js
Last active Feb 16, 2016
Options for passing multiple data down a promise chain
View promise_chains.js
// Promises can only resolve (return) a single value
// Sometimes, you want to collect multiple values as you progress through a promise chain
// e.g. Customer, Product, Basket, Payment Details
//
// I can only think of three options for handling this type of scenario (below)
// NB: Assume that FOO, BAR & BAZ are the result of some complex action (DB query etc.)
//
// What are the Pro's & Cons?
// Are there others?
@craig552uk
craig552uk / test_errors.js
Created Feb 15, 2016
The Right and Wrong way to use Errors in Promises
View test_errors.js
//
// Wrong ways to use Errors in Promises
//
// Passes Error constructor to next step in Promise chain
Promise.resolve('foo').then(val => {
return Error('Bad Thing 1');
}).then(val => {
console.log('LOG 1', val);
@craig552uk
craig552uk / http_exceptions.py
Created Oct 21, 2014
A set of HTTP Exceptions for use in Request Handlers
View http_exceptions.py
# -*- coding: utf-8 -*-
#
# Author: Craig Russell <craig@craig-russell.co.uk>
# Simple exceptions for HTTP Errors
# http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
#
# Example:
#
# try:
# raise BadRequest()
@craig552uk
craig552uk / netwk.py
Created Sep 12, 2014
A netcat type thing in python
View netwk.py
#
# > telnet localhost 4000
# Trying 127.0.0.1...
# Connected to localhost.
# Escape character is '^]'.
# hello
# world
#
# Connection closed by foreign host.
@craig552uk
craig552uk / cache.py
Created Aug 8, 2014
A Simple Python Memory Cache Library
View cache.py
# -*- coding: utf-8 -*-
#
# A simple memory cache library
# Author: Craig Russell <craig@craig-russell.co.uk>
#
import time
class Cache(object):
@craig552uk
craig552uk / kis_link_checker.py
Last active Aug 29, 2015
KIS Widget Checker
View kis_link_checker.py
@craig552uk
craig552uk / basics_of_unix_philosophy
Last active May 10, 2021
Basics of the Unix Philosophy
View basics_of_unix_philosophy
Basics of the Unix Philosophy
=============================
Rule of Modularity: Write simple parts connected by clean interfaces
Rule of Clarity: Clarity is better than cleverness
Rule of Composition: Design programs to be connected with other programs
Rule of Separation: Separate policy from mechanism; separate interfaces from engines