Skip to content

Instantly share code, notes, and snippets.

View re-require.js
function reRequire(name) {
delete require.cache[require.resolve(name)];
return require(name);
}
View try-catch-oneliner.md

Try-catch oneliner

If you search npm with query try await you will find a big modules list (you can find it in the boottom).

What all this developers want is just more clear way to use try catch. All of them suggest to use:

const tryCatch = require('try-catch');
const [error, data] = tryCatch(JSON.parse, 'hello');
View alphabet.js
alert('Hej. Napisz tu litere polskiego alfabetu i zobacz, jak ta litera sie pisze w jezyku ukrainskim')
function isRussian(a) {
return /[А-Яа-я]/.test(a)
};
const data = {
'a' : 'а',
'b' : 'б',
View promisify.js
const fs = require('fs');
const readFile = promisify(fs.readFile);
readFile('./hello', 'utf8').then(console.log);
// outputs
'world';
function promisify(fn) {
return (...a) => {
return new Promise((resolve, reject) => {
View reverse-linked-list.js
function createList(array) {
var list = createNext(0, array);
return list;
}
function createNext(i, array) {
var result;
if (i < array.length) {
View hash.js
(function () {
'use strict';
var util = require('util'),
crypto = require('crypto'),
Writable = require('stream').Writable;
module.exports = function() {
var ret;
View Spaces.js
/* add spaces beetwen words
*
* "view f4" -> "view f4"
*/
function item(name, n) {
var str = '',
array = [],
spaces = [],
count = 0;
View edit.js
this.setValue = function(value) {
getEditConfig(function(config) {
Util.exec.if(!config.collaboration, function() {
Ace.setValue(value);
ConfigView.afterShow();
}, setFirepad);
});
};
function setFirepad(callback) {
@coderaiser
coderaiser / youtube.js
Last active Aug 29, 2015
express youtube
View youtube.js
(function() {
'use strict';
var express = require('express'),
app = express(),
ytdl = require('ytdl'),
EXT = 'mp4',
URL = 'https://www.youtube.com/watch?v=',
PORT = 8888;
View localStorage-pollyfill.js
if (!window.localStorage) {
var Storage = function() {
/* приватный переключатель возможности работы с кэшем */
var StorageAllowed,
Data = {};
/* функция проверяет возможно ли работать с кэшем каким-либо образом */
this.isAllowed = function() {
return StorageAllowed;
};