Skip to content

Instantly share code, notes, and snippets.

View dannycroft's full-sized avatar

Danny Croft dannycroft

View GitHub Profile
@dannycroft
dannycroft / wrap.js
Created February 12, 2014 14:45
View how Chrome wraps all JavaScript entered into the Developer Tools
// Open Dev Tools console and enter
!(function a(){ debugger; }());
// Then you should see the wrapping
with ((console && console._commandLineAPI) || {}) {
!(function a(){ debugger;}())
}
// dollar selector
function $(C, P) {
P = P || document;
return /:first$/.test(C) ? (P = P.querySelector(C.slice(0, -6))) ? [P] : [] : [].slice.call(P.querySelectorAll(C))
}
// simple utility to add an event listener
$.on = function (CSS, parentNode, type, handler, capture) {
// in case parentNode is missing
if (typeof type !== 'string') {
<!DOCTYPE html>
<title>Animations</title>
<body>
<script>
function createAndAnimate(part) {
var element = document.createElement('pre');
element.textContent = part;
document.body.appendChild(element);
element.animate(
@dannycroft
dannycroft / angular-ga.js
Created October 16, 2014 16:02
Angular GA
(function(angular) {
angular.module('analytics', ['ng']).service('analytics', [
'$rootScope', '$window', '$location', function($rootScope, $window, $location) {
var track = function() {
$window._gaq.push(['_trackPageview', $location.path()]);
};
$rootScope.$on('$viewContentLoaded', track);
}
]);
Sinatra::Application.routes["GET"].each do |route|
before do
// All the things
end
end
function Words(str) {
this._str = str;
}
Words.prototype[Symbol.iterator] = function() {
var re = /\S+/g;
var str = this._str;
return {
next: function() {
@dannycroft
dannycroft / remove.sh
Created April 9, 2015 13:43
Docker - Remove all images and containers
#!/bin/bash
# Delete all containers
docker rm $(docker ps -a -q)
# Delete all images
docker rmi $(docker images -q)
@dannycroft
dannycroft / gist:930fe73318e1fa1a14c1
Created April 14, 2015 09:58
Docker - Last run container still running
# is the last run container still running?
docker inspect --format '{{.State.Running}}' $(docker ps -lq)
@dannycroft
dannycroft / gist:fbfd46fd1b4a071fc964
Created April 15, 2015 09:33
Elasticsearch shutdown via CURL
# Shutdown local node
curl -XPOST 'http://localhost:9200/_cluster/nodes/_local/_shutdown'
# Shutdown all nodes in the cluster
curl -XPOST 'http://localhost:9200/_shutdown'