This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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 : ''; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* http://jsfiddle.net/Zp3MZ/1/ */ | |
$(function() { | |
var objs = [{'one':1},{'two':2},{'three':3}]; | |
ajaxCall = function(i) { | |
return $.ajax({ | |
url:'/echo/html/', | |
method: 'POST', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//UK format - commas for thousands separator, full stop for decimal. | |
//d = number of decimal points. | |
String.prototype.number_format = function(d) { | |
var n = this; | |
var c = isNaN(d = Math.abs(d)) ? 2 : d; | |
var s = n < 0 ? "-" : ""; | |
var i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0; | |
return s + (j ? i.substr(0, j) + ',' : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + ',') + (c ? '.' + Math.abs(n - i).toFixed(c).slice(2) : ""); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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() {"+ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Array.prototype.contains = function(obj) { | |
var i = this.length; | |
while (i--) { | |
if (this[i] === obj) { | |
return true; | |
} | |
} | |
return false; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Do something 2 seconds after view loads | |
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
[NSTimer scheduledTimerWithTimeInterval:2.0 | |
target:self | |
selector:@selector(theAction) | |
userInfo:nil |
OlderNewer