Skip to content

Instantly share code, notes, and snippets.

View ehpc's full-sized avatar
💾

Eugene Maslovich ehpc

💾
View GitHub Profile
@ehpc
ehpc / scroll-to.js
Last active August 29, 2015 14:02
"Scroll to" plugin for jQuery. Automatically scrolls to selected element, usage: "$('#mydiv").scrollTo()".
jQuery.fn.extend({
/**
* Smooth scrolling to element
* @param interval Scrolling interval
* @param offset Offset from an element
*/
scrollTo: function (interval, offset) {
'use strict';
if (typeof interval === 'undefined') {
interval = 1000;
@ehpc
ehpc / btce-call-method.js
Created September 17, 2019 11:13
A Node.js module for calling BTC-e trading API methods
/**
* A module for calling the BTC-e trading API methods
* @author Eugene Maslovich <ehpc@ehpc.io>
*/
var https = require('https'),
querystring = require('querystring'),
crypto = require('crypto'),
nonce = Math.round((new Date()).getTime() / 1000);
@ehpc
ehpc / binance-postman-auth.js
Created September 17, 2019 11:27
Code for managing Binance authentication with Postman
let secret = pm.variables.get('secret-key'),
timestamp = Date.now(),
query = pm.request.url.query
.filter(x => !x.disabled && x.key !== 'signature')
.map(x => {
if (x.key === 'timestamp') {
return `${x.key}=${timestamp}`;
}
else {
return `${x.key}=${x.value}`;
@ehpc
ehpc / .editorconfig
Created November 26, 2019 19:36
Editorconfig 2 spaces
root = true
[*]
indent_style = space
indent_size = 2
tab_width = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
@ehpc
ehpc / nodejs-readline-example.js
Created January 24, 2020 20:18
Simple quiz using Node.JS readline module
const readline = require('readline');
const questions = [
['What does the fox say?', 'Yeeeee'],
['Will you be coding this weekend?', 'Whaaaatt?!']
];
const cmd = readline.createInterface({
input: process.stdin,
output: process.stdout
@ehpc
ehpc / nodejs-readline-nonrecursive-example.js
Created January 25, 2020 20:43
Node.JS readline usage without recursion
const readline = require('readline');
const questions = [
['Can the fox be recursive?', 'O_o'],
['Can readline be non-recursive?', 'Yep']
];
const cmd = readline.createInterface({
input: process.stdin,
output: process.stdout
@ehpc
ehpc / async-patterns.js
Created January 27, 2020 17:04
Examples of dIfferent async patterns in JavaScript
/**
* Разные асинхронные паттерны в JS, решающие одну и ту же задачу
*/
///////////////// callbacks ///////////////////////////////////
function asyncFunction(callback) {
setTimeout(callback.bind(this, 42), 100);
}
asyncFunction(console.log.bind(this, 'asyncFunction:'));
@ehpc
ehpc / async-is-not-asynchronous.js
Last active February 5, 2020 07:37
async keyword doesn't make your function asynchronous
function heavyFunc() {
const limit = Math.pow(10, 8);
let res = 0;
for (let i = 1; i < limit; i++) {
res += Math.atan2(i, i) * Math.random();
}
return res;
}
async function heavyFuncWithAsync() {
@ehpc
ehpc / nodejs-mongo-async-await.js
Created March 31, 2020 08:45
Node.JS MongoDb Async/Await
const MongoClient = require('mongodb').MongoClient;
const uri = 'mongodb://localhost:27017/';
const mongoClient = new MongoClient(uri, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
(async () => {
const connection = await mongoClient.connect();
@ehpc
ehpc / ramda-promises-compose.js
Last active July 17, 2023 03:29
How to compose promises with Ramda
// Custom promise-based compose
const composeWithPromise = (...args) =>
R.composeWith((f, val) => {
if (val && val.then) {
return val.then(f);
}
if (Array.isArray(val) && val.length && val[0] && val[0].then) {
return Promise.all(val).then(f);
}
return f(val);