Skip to content

Instantly share code, notes, and snippets.

View ischenkodv's full-sized avatar

Dmitri Ischenko ischenkodv

  • Ukraine, Kryvyi Rih
View GitHub Profile
@ischenkodv
ischenkodv / writable_stream.js
Created March 18, 2017 21:54
Example of writable stream in NodeJS.
const stream = require('stream');
const fs = require('fs');
class EchoStream extends stream.Writable {
_write(chunk, enc, next) {
console.log(chunk.toString());
next();
}
}
@ischenkodv
ischenkodv / fibonacci.php
Created October 28, 2015 08:54
Fibonacci function
function fibonacci($n) {
if (is_int($n)) {
return round(pow((sqrt(5)+1)/2, $n) / sqrt(5));
} else {
throw new Exception('Value should be an integer');
}
}
var fs = require('fs');
var files = ['foo.txt', 'bar.txt', 'baz.txt'];
var promises = [];
for (var i = 0; i < files.length; i++) {
promises.push(readFile(files[i]));
}
@ischenkodv
ischenkodv / strings.js
Created April 18, 2015 21:07
Unit tests for lesson 2
/**
* This is module to test.
*/
module.exports = {
camelCase: function(string) {
return string.replace(/-[a-z]/g, function(match) {
return match[1].toUpperCase() + match.slice(2);
});
},
dashSeparated: function(string) {
describe('findByNavigator()', function() {
var geolocator, fnDone, fnFail;
beforeEach(function() {
geolocator = new Geolocator({language: 'fi'});
});
it('can find user location', function() {
var location, address, components;
@ischenkodv
ischenkodv / RAFPlugin.js
Created February 28, 2015 20:24
Jasmine plugin to test functions with requestAnimationFrame.
/**
* Jasmine RequestAnimationFrame: a set of helpers for testing funcionality
* that uses requestAnimationFrame under the Jasmine BDD framework for JavaScript.
*/
;(function() {
var index = 0,
callbacks = {};
function MockRAF(global) {
@ischenkodv
ischenkodv / AsyncQueueSpec.js
Created February 28, 2015 20:22
Unit tests for AsyncQueue
describe('run()', function() {
var realNextFrame, realCancelFrame;
beforeEach(function() {
jasmine.clock().install();
jasmine.RequestAnimationFrame.install();
realNextFrame = window.nextFrame;
realCancelFrame = window.cancelFrame;
window.nextFrame = window.requestAnimationFrame;
@ischenkodv
ischenkodv / AsyncQueue.js
Created February 28, 2015 20:17
Asynchronous queue implementation. Functions could be added to queue and executed one by one immediately, or with intervals or in the next frame (using requestAnimationFrame).
;(function(window) {
'use strict';
/**
* AsyncQueue allows you to create a queue of function to be executed via
* setTimout that guaranteed to run in order. This can enable to run
* process-intensive operations without locking up UI.
*
* @constructor
@ischenkodv
ischenkodv / joomla_json.php
Created November 30, 2014 00:35
Return JSON data from action of Joomla controller.
/**
* JSON response from controller's action.
*/
public function run( )
{
JFactory::getDocument()->setMimeEncoding( 'application/json' );
JResponse::setHeader('Content-Disposition','attachment;filename="progress-report-results.json"');
$data = array(
'foo' => 'bar'
@ischenkodv
ischenkodv / ie_conditionals.html
Created February 11, 2014 21:11
Adding class names depending on Internet Explorer version.
<!DOCTYPE html>
<!--[if lt IE 7 ]> <html class="ie6" lang="en"> <![endif]-->
<!--[if IE 7 ]> <html class="ie7" lang="en"> <![endif]-->
<!--[if IE 8 ]> <html class="ie8" lang="en"> <![endif]-->
<!--[if IE 9 ]> <html class="ie9" lang="en"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html lang="en"> <!--<![endif]-->
<body></body>
</html>