Skip to content

Instantly share code, notes, and snippets.

@sax1johno
sax1johno / Contract Killer 3.md
Created Nov 1, 2016 — forked from malarkey/Contract Killer 3.md
The latest version of my ‘killer contract’ for web designers and developers
View Contract Killer 3.md

Contract Killer

The popular open-source contract for web professionals by Stuff & Nonsense

  • Originally published: 23rd December 2008
  • Revised date: March 15th 2016
  • Original post

View tcp.js
// LINE 160 of seneca-transport/lib/tcp.js
reconnect.on('disconnect', function (err) {
seneca.log.debug('client', type, 'disconnect', spec, topic, clientOptions,
(err && err.stack) || err)
_.find(connections, { clientOptions: clientOptions }).setup = false // This code fails. Wrapping an "undefined" guard around _.find fixes the issue.
})
View Seneca_Client_Error_Reproduce.js
seneca.ready(function() {
client = seneca.client({type: 'tcp'});
})
@sax1johno
sax1johno / index.css
Created Sep 20, 2016
Baseball Example created by sax1johno - https://repl.it/DdNO/3
View index.css
Empty file
@sax1johno
sax1johno / README.md
Created Aug 29, 2016
Cached Astronomy Picture of the Day
View README.md

This flow will download the latest Astronomy Picture of the Day (APOD) from Nasa.gov and caches in memory.

It hits the API once every 24 hours, so you don't have to worry about reaching your quota.

This flow demonstrates a technique in caching data that can be used for other sites as well - for example, you can create your own "xxx of the day" from any site that offers a random API by simply calling that random API once every 24 hours (you can change this interval) and caching the result. Calls to the API will read from the cached version.

NOTE: to use this flow you must obtain a free API key from data.nasa.gov.

View Docker Rolling Update
I just worked out another flow to have Zero downtime (mainly for web apps).
Proxy
We use jwilder/nginx-proxy to handle routing to app servers, this will assist us in dynamically routing requests to services.
First Deploy
For the first deploy run docker-compose --project-name=app-0001 up -d.
View DockerScript.sh
docker rmi $( docker images -q -f dangling=true)
@sax1johno
sax1johno / Nativescript-WebViewWithLinks.js
Created Aug 12, 2016
Code in NativeScript to overload URL's in a rendered web page and display them in a content-appropriate way.
View Nativescript-WebViewWithLinks.js
@sax1johno
sax1johno / remove-docker-containers.md
Created Aug 2, 2016 — forked from ngpestelos/remove-docker-containers.md
How to remove unused Docker containers and images
View remove-docker-containers.md
  1. Delete all containers

     $ docker ps -q -a | xargs docker rm
    

-q prints only the container IDs -a prints all containers

Notice that it uses xargs to issue a remove container command for each container ID

  1. Delete all untagged images
View ReverseString_step3.js
var reverseString = function(stringToReverse) {
var finalString = []; // I prefer to use arrays instead of strings.
// loop through the string, starting at the end.
for (var i = stringToReverse.length; i > 0; i--) {
// push the character at the current index into the finalString array
finalString.push(stringToReverse[i]);
}
// Join the characters in the array into a string and return the string.
return finalString.join('');
}