Skip to content

Instantly share code, notes, and snippets.

View dimorphic's full-sized avatar
🤖
*void 0*

Sabin Tudor dimorphic

🤖
*void 0*
View GitHub Profile
@dimorphic
dimorphic / 0_reuse_code.js
Created December 13, 2013 09:03
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
function checkPopupBlocked(poppedWindow) {
setTimeout(function(){doCheckPopupBlocked(poppedWindow);}, 5000);
}
function doCheckPopupBlocked(poppedWindow) {
var result = false;
try {
if (typeof poppedWindow == 'undefined') {
app.directive('infiniteScroll', [
'$rootScope', '$window', '$timeout', function($rootScope, $window, $timeout) {
return {
link: function(scope, elem, attrs) {
var checkWhenEnabled, handler, scrollDistance, scrollEnabled;
$window = angular.element($window);
elem.css('overflow-y', 'scroll');
elem.css('overflow-x', 'hidden');
elem.css('height', 'inherit');
scrollDistance = 0;
@dimorphic
dimorphic / randomName
Created December 10, 2014 23:35
generate random username
// generate a random username
var randomName = function() {
var animals = ['pigeon', 'seagull', 'bat', 'owl', 'sparrows', 'robin', 'bluebird', 'cardinal', 'hawk', 'fish', 'shrimp', 'frog', 'whale', 'shark', 'eel', 'seal', 'lobster', 'octopus', 'mole', 'shrew', 'rabbit', 'chipmunk', 'armadillo', 'dog', 'cat', 'lynx', 'mouse', 'lion', 'moose', 'horse', 'deer', 'raccoon', 'zebra', 'goat', 'cow', 'pig', 'tiger', 'wolf', 'pony', 'antelope', 'buffalo', 'camel', 'donkey', 'elk', 'fox', 'monkey', 'gazelle', 'impala', 'jaguar', 'leopard', 'lemur', 'yak', 'elephant', 'giraffe', 'hippopotamus', 'rhinoceros', 'grizzlybear'];
var colors = ['silver', 'gray', 'black', 'red', 'maroon', 'olive', 'lime', 'green', 'teal', 'blue', 'navy', 'fuchsia', 'purple'];
return colors[Math.floor(Math.random() * colors.length)] + '-' + animals[Math.floor(Math.random() * animals.length)];
};
/* Detects ftp | ftps | http | https and prepends http:// if none */
function ensureUrlScheme(url) {
if (!/^(((f|ht)tps?)|chrome-extension):\/\//i.test(url)) {
url = "http://" + url;
}
return url;
}
/* Detects the scheme of the url, removes it */
function detachUrlScheme(url) {
@dimorphic
dimorphic / angular-replace-behaviour
Created January 15, 2015 17:54
replicate behaviour of angular 'replace' in directives (will be removed in future angularjs versions)
/// Replace element with it's first child
Utils.replaceWithChild = function(element) {
var child = angular.element(element[0].firstChild);
Utils.mergeAttributes(element, child);
element.replaceWith(child);
}
/// Copy attributes from sourceElement to targetElement, merging their values if the attribute is already present
Utils.mergeAttributes = function(sourceElement, targetElement) {
var arr = sourceElement[0].attributes;
@dimorphic
dimorphic / index.js
Created February 28, 2015 11:53
requirebin sketch
// example using the raf module from npm. try changing some values!
var requestAnimationFrame = require("raf")
var canvas = document.createElement("canvas")
canvas.width = 500
canvas.height = 500
document.body.appendChild(canvas)
var context = canvas.getContext("2d")
@dimorphic
dimorphic / index.js
Created February 28, 2015 11:54
requirebin sketch
var inherits = require('inherits');
var Game = require('crtrdg-gameloop');
var Entity = require('crtrdg-entity');
var Keyboard = require('crtrdg-keyboard');
var canvas = document.createElement('canvas');
canvas.id = 'game';
var body = document.getElementsByTagName('body')[0];
@dimorphic
dimorphic / math.uuid.js
Created March 3, 2015 23:08
Math.uuid
/*!
Math.uuid.js (v1.4)
http://www.broofa.com
mailto:robert@broofa.com
Copyright (c) 2010 Robert Kieffer
Dual licensed under the MIT and GPL licenses.
*/
/*
@dimorphic
dimorphic / keycode.js
Created September 24, 2015 22:23
keycodes
/**
* A list of JavaScript key codes to reference by name.
* From 'Foundation HTML5 Animation with JavaScript': http://amzn.com/1430236655?tag=html5anim-20
*/
var keycode = {
BACKSPACE: 8,
TAB: 9,
ENTER: 13,
COMMAND: 15,