Skip to content

Instantly share code, notes, and snippets.

@tkh44
tkh44 / later.js
Created November 6, 2013 22:03
Run a function repeatedly on a specific interval
/**
* Run a function repeatedly on a specific interval
* @param {function} fn callback to run
* @param {number} interval time in ms between runs
* @param {boolean} immediate
* @param {...n} args
* @returns {object} timer object. Call cancel() to stop timer
*/
later: function(fn, interval, immediate, args) {
var cbArgs = _.toArray(arguments).slice(3);
@tkh44
tkh44 / image
Created November 12, 2013 22:42
base64Image
/9j/4AAQSkZJRgABAQAAAQABAAD/4QFsRXhpZgAATU0AKgAAAAgABwEPAAIAAAAFAAAAYgEQAAIAAAAKAAAAZwEbAAUAAAABAAAAcQEyAAIAAAAUAAAAeQExAAIAAAAFAAAAjQEaAAUAAAABAAAAkodpAAQAAAABAAAAmgAAAABBcHBsZWlQb2QgdG91Y2gAAABIAAAAATIwMTM6MTE6MTIgMTY6NDE6NDEANy4wLjMAAABIAAAAAQANpAUAAwAAAAEAIQAAkgkAAwAAAAEAGAAAoAEAAwAAAAEAAQAAoAMABAAAAAEAAAeQoAIABAAAAAEAAAogpAMAAwAAAAEAAAAAohcAAwAAAAEAAgAAkAQAAgAAABQAAAE8iCIAAwAAAAEAAgAAkAMAAgAAABQAAAFQkgcAAwAAAAEABQAApAIAAwAAAAEAAAAAowEAAwAAAAEAAQAAAAAAADIwMTM6MTE6MTIgMTY6NDE6NDEAMjAxMzoxMToxMiAxNjo0MTo0MQD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAARCAogB5ADASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEB
@tkh44
tkh44 / photo-viewer.less
Last active December 28, 2015 06:09
Simple spinner based on pace.js spinner
.spinner {
display: block;
position: absolute;
z-index: 2000;
top: 50%;
right: 15px;
width: 14px;
height: 14px;
margin-top: -9px;
border: solid 2px transparent;
@tkh44
tkh44 / spinner.less
Created November 14, 2013 20:45
Simple Chase Spinner, based on Pace's Implemenation
.spinner (@color: @white, @top: 50%, @left: 50%, @width: 24%, @height: 25%, @radius: 50%, @duration: 600ms) {
display: block;
position: absolute;
z-index: 2000;
top: @top;
left: @left;
width: @width;
height: @height;
margin-left: -@width/2;
margin-top: -@height/2;
(function() {
var oldToJSON = Backbone.Model.prototype.toJSON;
Backbone.Model.prototype.toJSON = function() {
var json = oldToJSON.apply(this, arguments),
excludeFromJSON = this.excludeFromJSON || [];
return humps.decamelizeKeys(_.omit(json, excludeFromJSON));
};
})();
@tkh44
tkh44 / FileController.js
Last active October 1, 2025 03:05
Simple file upload for sails.js
module.exports = {
get: function (req, res) {
res.sendfile(req.path.substr(1));
},
_config: {
rest: false,
shortcuts: false
}
};
// www/javascripts/application.js
window.tacoApp = angular.module('tacoApp', ['TacoModel', 'ngTouch']);
@tkh44
tkh44 / custom-inputs.html
Last active August 29, 2015 13:57
Angular template for dealing with custom fields defined by a json object.
<div ng-switch="input.displayType" ng-class="input.displayType">
<div ng-switch-when="Input" class="text-input custom-input"
ng-class="input.options.multiline ? 'multiline' : 'singleline'">
<span class="category">{{input.name}}</span>
<span class="info">
<input ng-if="!input.options.multiline && input.dataType === 'NUMBER'"
type="{{input.dataType}}" name="{{input.code}}" ng-model="input.value"
required="input.required" min="0" ng-disabled="disabled">
<input ng-if="!input.options.multiline && input.dataType === 'TEXT'"
@tkh44
tkh44 / fixedButtonContainer.js
Created March 24, 2014 21:09
So you can have a fixed button container at the bottom of your ng-view
ticketApp.directive('fixedButtonContainer', function($timeout) {
return {
restrict: 'A',
scope: {
mainView: '@'
},
link: function($scope, $element, attrs) {
$scope.$container = angular.isDefined($scope.mainView) ? $($scope.mainView): $element.closest('[ng-view]');
if (!$scope.$container) return;
@tkh44
tkh44 / focusElement.js
Created March 24, 2014 21:46
Focus an element. Use the focus-delay="" to delay the focus x amount of ms
ticketApp.directive('focusElement', function($timeout) {
return {
restrict: 'A',
scope: {
focusElement: '@',
focusDelay: '@'
},
link: function($scope, $element, $attrs) {
$scope.$focusElement = angular.isDefined($scope.focusElement) ? $($scope.focusElement): $element;