Skip to content

Instantly share code, notes, and snippets.

@rd13
rd13 / draggable.coffee
Created October 3, 2014 09:43
Angular Draggable Directive
'use strict'
angular.module('ip')
.directive('draggable', ($document) ->
restrict: "EA"
link: (scope, element, attr) ->
pos_y = pos_x = drg_h = drg_w = 0
@rd13
rd13 / bestsum.js
Created May 25, 2012 09:43
Find the best sum of numbers in an array for a given value.
//jsFiddle: http://jsfiddle.net/CuDzh/3/
$(function() {
function bestSum(numbers, sum) {
l = function(index, total, solution) {
index = index ? index : 0;
total = total ? total : 0;
solution = solution ? solution : '';
@rd13
rd13 / gist:2888660
Created June 7, 2012 12:52
Javascript Generate Password
generatePassword = function(l) {
l = l ? l : 8;
var charset = "abcdefghijklnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
retVal = "";
for (var i = 0, n = charset.length; i < l; ++i) {
retVal += charset.charAt(Math.floor(Math.random() * n));
}
return retVal;
}
@rd13
rd13 / gist:3136066
Created July 18, 2012 13:00
jQuery multiple deferreds
/* http://jsfiddle.net/Zp3MZ/1/ */
$(function() {
var objs = [{'one':1},{'two':2},{'three':3}];
ajaxCall = function(i) {
return $.ajax({
url:'/echo/html/',
method: 'POST',
@rd13
rd13 / gist:3228477
Created August 1, 2012 16:29
TR Inset Shadow CSS
/* http://jsfiddle.net/KtPdt/8/ */
td {
background-color: rgba(255, 255, 255, 0.8);
-webkit-box-shadow: inset 0px 11px 8px -10px orange,
inset 0px -11px 8px -10px orange;
padding: 5px;
}
td:first-child {
-webkit-box-shadow: inset 10px 11px 8px -10px orange,
@rd13
rd13 / gist:3793748
Created September 27, 2012 12:31
Mongoose / MongoDB Data Types
mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/test');
Schema = mongoose.Schema;
console.log(Schema.Types);
{ String: [Function: SchemaString],
Number: [Function: SchemaNumber],
Boolean: { [Function: SchemaBoolean] '$conditionalHandlers': { '$in': [Function: handleArray] } },
DocumentArray: [Function: DocumentArray],
@rd13
rd13 / gist:4038271
Created November 8, 2012 11:29
Disqus / Handlebars Block Helper. (Node / Express hbs)
//A handlebars block helper for embedding Disqus.
var hbs = require('hbs');
hbs.registerHelper('disqus', function(slug) {
var value = "<div id='disqus_thread'></div>"+
"<script type='text/javascript'>"+
"var disqus_shortname = '';"+
"var disqus_identifier = '/"+slug+"';"+
"(function() {"+
@rd13
rd13 / gist:4079164
Created November 15, 2012 15:25
in_array function in Javascript
Array.prototype.contains = function(obj) {
var i = this.length;
while (i--) {
if (this[i] === obj) {
return true;
}
}
return false;
}
@rd13
rd13 / gist:4454684
Created January 4, 2013 18:18
Objective-C UICollectionViewCell Iteration
//cv = UICollectionView
for (int section = 0; section < [cv numberOfSections]; section++) {
for (int row = 0; row < [cv numberOfItemsInSection:section]; row++) {
NSIndexPath* cellPath = [NSIndexPath indexPathForRow:row inSection:section];
//Cast to a custom cell: "GameCollectionViewCell"
GameCollectionViewCell *cell = (GameCollectionViewCell *) [cv cellForItemAtIndexPath:cellPath];
NSLog(@"%i",cell.lbl.tag);
}
}
@rd13
rd13 / gist:4457820
Created January 4, 2013 22:11
Objective-C Xcode Decrementing Fluid Progress Bar
//.h
//IBOutlet UIProgressView *pv;
//.m
- (void)viewDidLoad
{
[super viewDidLoad];
pv.progress = 1.0;
[self performSelectorOnMainThread:@selector(makeMyProgressBarMoving) withObject:nil waitUntilDone:NO];