Skip to content

Instantly share code, notes, and snippets.

View stephenwil's full-sized avatar

Stephen Wilson stephenwil

  • Scotia Technology Solutions Ltd
  • Scotland
View GitHub Profile
@stephenwil
stephenwil / promiseGoodPractice.js
Created August 11, 2016 08:10
Better promise constructs
function ExampleAPIHandler(downChainResponse, otherdata, next) {
var promiseArray = [];
var respJSON = {
body: {},
success: true,
warnings: [],
errors: []
};
@stephenwil
stephenwil / gist:bc3649ddbb3a8f5461bcc458a562411f
Created August 11, 2016 10:24
Loopback : promise and the access token model
/**
* The Access Token model in loopback doesn't support Promises out-the-box, and it won't work with Bluebird Promisify
*/
util.tokenValidateAsync = function(token) {
return new Promise(function(resolve, reject) {
token.validate(function(err, isValid){
if (!err) {
resolve(isValid);
}
else {
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 6.4.0)
var b = N.toString(2);
var gap = 0, biggestGap = 0;
console.log(b);
@stephenwil
stephenwil / install_jenkins_plugin.sh
Last active October 28, 2016 09:17 — forked from micw/install_jenkins_plugin.sh
Script to install one or more jenkins plugins including dependencies while jenkins is offline
#!/bin/bash
set -e
if [ $# -eq 0 ]; then
echo "USAGE: $0 plugin1 plugin2 ..."
exit 1
fi
plugin_dir=~/jenkins/plugins
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@stephenwil
stephenwil / Context.tsx
Created May 29, 2018 09:59
Typescript HOC Context
export const withContext = <P extends {}>(Component: React.ComponentType<P>) =>
class WithContext extends React.PureComponent<P & IAppContext> {
render() {
return (
<AppContext.Consumer>
{(context: any) => <Component {...this.props} {...context} />}
</AppContext.Consumer>
);
}
};
const mapEnum = (type: any, value: any) => {
const x = findKey(type, (v: any,i: any, a: any) => {
// console.log(v,i,a,v2);
return v === value
});
console.log(x);
return x;
}
@stephenwil
stephenwil / scottish-schools-2018.json
Last active April 17, 2019 14:33
Scottish Schools at 2018
This file has been truncated, but you can view the full file.
[
{
"SeedCode": "8212627",
"LA Name": "North Ayrshire",
"Centre Type": "Local Authority",
"School Name": "Abbey Primary School",
"Address 1": "Claremont Crescent",
"Address 2": "",
"Address 3": "KILWINNING",
"Post code": "KA13 7HG",
@stephenwil
stephenwil / index.html
Last active May 23, 2019 10:00
An icon set in one complete <svg> block, making use of <symbol> such that you can refer to the svgs via <use> rather than inline them.
<html>
<head>
</head>
<body>
<svg xmlns="http://www.w3.org/2000/svg" xlink="http://www.w3.org/1999/xlink">
<use xlink:href="https://gist.github.com/stephenwil/b0ec7b72daecdbe562ec248ee9b4480e#file-openweather-api" x="100" y="300" />
</svg>
</body>
</html>