This file contains hidden or 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
function sleepSort(arr) { | |
arr.forEach((n) => setTimeout(() => console.log(n), n)) | |
} | |
const arr = [9, 5, 3, 99, 11, 2, 0] | |
sleepSort(arr) | |
/* stdout: | |
0 | |
2 |
This file contains hidden or 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
code | state | pop_2014 | |
---|---|---|---|
AL | Alabama | 4849377 | |
AK | Alaska | 736732 | |
AZ | Arizona | 6731484 | |
AR | Arkansas | 2966369 | |
CA | California | 38802500 | |
CO | Colorado | 5355866 | |
CT | Connecticut | 3596677 | |
DE | Delaware | 935614 | |
DC | District of Columbia | 658893 |
This file contains hidden or 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
license: mit |
This file contains hidden or 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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web; | |
using System.Data.Common; | |
using System.Data.Linq; | |
namespace MyApp.Models.DataContextWrapper | |
{ | |
public interface IDataContextWrapper |
This file contains hidden or 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
license: mit |
This file contains hidden or 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
import NodeCache from 'node-cache'; // or 'redis' | |
class CacheService { | |
constructor(ttlSeconds) { | |
// this could also be redis | |
this.cache = new NodeCache({ stdTTL: ttlSeconds, checkperiod: ttlSeconds * 0.2, useClones: false }); | |
} | |
get(key, storeFunction) { |
This file contains hidden or 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
// for counting words in a string | |
var words="Hi there and hello there. Welcome and hello there."; | |
var wordcnt = words.replace(/[^\w\s]/g, "").split(/\s+/).reduce(function(map, word){ | |
map[word] = (map[word]||0)+1; | |
return map; | |
}, Object.create(null)); |
This file contains hidden or 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
// via http://www.klauskomenda.com/code/javascript-inheritance-by-example/ | |
// create constructor function for base "class" | |
function Vehicle(hasEngine, hasWheels) { | |
this.hasEngine = hasEngine || false; | |
this.hasWheels = hasWheels || false; | |
} | |
// create constructor function | |
function Car (make, model, hp) { | |
this.hp = hp; |
This file contains hidden or 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
// jquerify.js // https://github.com/bgrins/devtools-snippets // Add jQuery to any page that does not have it already. | |
(function() { | |
if (!window.jQuery) { | |
var s = document.createElement('script'); | |
s.setAttribute('src', '//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js'); | |
document.body.appendChild(s); | |
console.log('jquery loaded!'); |
This file contains hidden or 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
license: mit |
NewerOlder