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
var testUtil = { | |
/** | |
* Fails the assertion with the message provided. | |
*/ | |
failWith: function (msg) { | |
AssertionResult.setFailure(true); | |
AssertionResult.setFailureMessage(msg); | |
}, | |
isArray: function (obj) { |
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
const https = require('https'); | |
// This being a dirty prototype, I'm not concerned about checking for min/max values for this... | |
const maxPages = process.argv[2] || 3; | |
function getStreams(pages, offset, data, cb){ | |
// Offset could be too far. First response would include total streams (res._total). It also has links to next page... | |
const req = https.get({ hostname: 'api.twitch.tv', path: '/kraken/streams?stream_type=live&offset=' + offset }, function(res){ | |
var body = ''; |
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
/* VIEW.html | |
<style> | |
.container { | |
margin: 10px auto; | |
padding: 10px; | |
border: 1px solid #333; | |
display: block; | |
overflow: auto; | |
text-align: center; | |
} |
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
<?php | |
// Number of times to simulate selection | |
const MAX = 500000; | |
// Probability of selecting promoted element (40% more often than normal items) | |
const PROMOTED_PROB = 0.7142857142857143 /* 1 / 1.4 */; | |
$total = 0; | |
$in = array_map(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
/** | |
* @param int $nid | |
* @param array $props | |
* @param resource $xml | |
* @param bool $includeHidden | |
* @return array | |
*/ | |
function getChildrenNodes($nid, array $props, &$xml, $includeHidden = false) { | |
$node = xtree_get_node($xml, "/story/body/tree//node[@id='$nid']"); |
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
/** | |
* Attempt to load a script from a popular ad network. Ad blockers will intercept the HTTP request. | |
* | |
* @param {string} url | |
* @return {Promise} | |
*/ | |
function detectAdBlockerAsync(url){ | |
var def = $.Deferred(); | |
var script = document.createElement('script'); |
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
// CLI command | |
// -p = production (uglify) | |
// -d = source maps | |
// --watch (optional) | |
webpack index.js --output-file bundle.min.js -p -d --progress |
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
// This snippet came from some website and is not original | |
function saveTextAsFile() | |
{ | |
var textToWrite = 'lorem ipsum'; | |
var textFileAsBlob = new Blob([textToWrite], {type:'text/plain'}); | |
var fileNameToSaveAs = 'html5-blob-to-file.txt' | |
var downloadLink = document.createElement('a'); | |
downloadLink.download = fileNameToSaveAs; | |
downloadLink.innerHTML = "Download File"; |
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
// As of this writing, the example on https://github.com/steida/gulp-closure-compiler doesn't | |
// explain how to compile your project using Google's Closure Library. | |
// Since the newest version of the compiler doesn't need a deps file anymore, we just need | |
// to provide all our module definitions (files with goog.provide) to the task src. | |
gulp.task('build', function () { | |
// Specify where your Closure Library is stored --------------------------vvvv | |
gulp.src(['main.js', 'src/**/*.js', 'node_modules/closure-library/closure/goog/**/*.js']) | |
// Everything else is the same as in the docs |
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
<?php | |
/** | |
* Class Handler | |
* | |
* Playing around with reflection & DI. Handler is a routing class (think Express [node.js] or Slim [php]), | |
* with a built-in dependency injection system inspired by Angular.js. | |
* | |
* Consider this: | |
* - Use annotations in the handler callback to specify what class needs to be instantiated? |
NewerOlder