Skip to content

Instantly share code, notes, and snippets.

View samgiles's full-sized avatar
🗺️

Sam Giles samgiles

🗺️
  • Citymapper
  • London
View GitHub Profile
@samgiles
samgiles / flatMap.js
Created June 20, 2014 11:32
Javascript flatMap implementation
// [B](f: (A) ⇒ [B]): [B] ; Although the types in the arrays aren't strict (:
Array.prototype.flatMap = function(lambda) {
return Array.prototype.concat.apply([], this.map(lambda));
};
@samgiles
samgiles / polyio-names.js
Last active September 30, 2023 02:49
Polyfill.io Name resolution pseudocode
// Functional Helper: When lambda returns an array, compose concat and map to return a flattened result.
// See https://gist.github.com/samgiles/762ee337dff48623e729 for an example
Array.prototype.flatMap = function(lambda) {
return Array.prototype.concat.apply([], this.map(lambda));
};
// Mock, imagine this is some function that maps a modernizr test name to the polyfill.io nomenclature, if it doesn't map,
// it must return the name as is. Must always be an array.
function getListOfPolyFillsForModernizrTest(name) {
var mock = {
@samgiles
samgiles / .travis.yml
Last active September 22, 2015 14:55 — forked from triblondon/.travis.yml
sudo: false
language: node_js
node_js:
- "0.10"
before_install:
- npm install -g Financial-Times/origami-build-tools#node-0.10
- obt install
script:
- obt test
- obt verify
@samgiles
samgiles / dom_recycler
Created July 17, 2014 15:42
Old DOM Element recycling test
<!DOCTYPE html>
<html>
<head>
<title>DOM Recycler</title>
<style>
/* Styles not relevant to scrolling (just to make the demo look neat and tidy) */
body { font-family: sans-serif; -webkit-text-size-adjust: 100% }
#
var resolvedPolyfills = {};
polyfills.forEach(function(polyfill) {
resolvers.forEach(function(resolver) {
resolver(polyfill).forEach(function(targetPolyfill) {
resolvedPolyfills[targetPolyfill.name] = targetPolyfill
})
})
});
@samgiles
samgiles / npmcleaner
Created August 1, 2014 13:30
Remove all Node modules safely
# Not global:
npm ls -p --depth=0 | awk -F/node_modules/ '{print $2}' | grep -vE '^(npm)$' | xargs npm rm
# Global:
npm ls -gp --depth=0 | awk -F/node_modules/ '{print $2}' | grep -vE '^(npm)$' | xargs npm -g rm
Set up key for github
make sure brew is installed
make sure git is installed with brew
(Sourcetree issues..) Use HTTPS (Auth issues are just too much) Github for Mac
git clone at the command line?
try `sudo gem install ruby` if failed:
rvm install ruby
@samgiles
samgiles / gist:36ebe62656ab1177c654
Last active August 29, 2015 14:06
AWS Instance Type Information
{
"families": [{
"description": "Micro instances are a low-cost instance option, providing a small amount of CPU resources. They are suited for lower throughput applications, and websites that require additional compute cycles periodically, but are not appropriate for applications that require sustained CPU performance. Popular uses for micro instances include low traffic websites or blogs, small administrative applications, bastion hosts, and free trials to explore EC2 functionality.",
"name": "Micro instances",
"types": [{
"architectures": ["x86_64", "i386"],
"cpu": {
"cores": 1,
"units": "Variable"
},
@samgiles
samgiles / check_health
Last active August 29, 2015 14:06
Simple __health endpoint NRPE check
#!/usr/bin/env python
import argparse
import urllib2
import json
import sys
NAGIOS_OK = 0
NAGIOS_WARN = 1
NAGIOS_CRIT = 2
@samgiles
samgiles / gist:735178b552c56e9d87ef
Created September 24, 2014 10:09
All GISTS by samgiles are licensed using the MIT license unless otherwise stated.
The MIT License (MIT)
Copyright (c) 2014 Samuel Giles
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions: