Skip to content

Instantly share code, notes, and snippets.

const convertUnitToEGLD = (unit) => {
return unit / 1e18
}
const isReadyToRestake = (delegatedTokens, apr, claimableRewards) => {
const fees = 1355e-7
const stakingPeriodInDays = 365
const date = Date.now()
const numberOfDay = () => {
@dnnaji
dnnaji / index.js
Last active July 14, 2020 00:02 — forked from rauchg/Readme.md
// NOTE: this file belongs in `lib/`! [gist limitation]
import request from 'request-promise';
const URL = 'https://api.bitcoinaverage.com/ticker/global/USD';
export default async function (req, res) {
const price = await request(URL, { json: true });
return `The price is ${price.last} as of ${price.timestamp}`;
}
@dnnaji
dnnaji / string-utils.js
Created June 7, 2020 19:43 — forked from jonlabelle/string-utils.js
Useful collection of JavaScript string utilities.
// String utils
//
// resources:
// -- mout, https://github.com/mout/mout/tree/master/src/string
/**
* "Safer" String.toLowerCase()
*/
function lowerCase(str) {
return str.toLowerCase();
@dnnaji
dnnaji / waterfall.js
Created September 27, 2019 05:41
Partition Problem react
// https://codesandbox.io/s/x260l8963z
// https://www.damiannicholson.com/posts/2018/07/14/creating-a-layout-like-pinterest-with-react-and-the-partition-problem/
import React, { Component } from 'react';
/**
* We need to partition the Waterfall images in to N sets where N is the number
* of columns dictated by the organiser, and the sum of numbers in each set is almost
* equal.
*
* This is a fast greedy solution to that problem https://stackoverflow.com/q/6669460.
@dnnaji
dnnaji / index.js
Created January 20, 2019 00:48
Now v2 local dev for Node.js
require("dotenv-safe").config();
const url = require("url");
const now = require("./now.json");
const routes = now.routes
.filter(route =>
now.builds.some(
build =>
build.src.startsWith(`${route.dest.substring(1)}/`) &&
@dnnaji
dnnaji / dev-server.js
Created January 8, 2019 04:46 — forked from roelvan/dev-server.js
NOW v2 Local DEV env Node.js
require('dotenv').config();
const http = require('http');
const url = require('url');
// import NOW SETTINGS
const now = require('./now.json');
const PORT = process.env.PORT || 3030;
const routes = now.routes.reduce((map, route) => {
@dnnaji
dnnaji / scrape.dart
Last active December 1, 2018 19:07 — forked from kui/scrape.dart
a web scraping script with Dart and html5
import 'dart:io';
import 'dart:async';
import 'package:html/parser.dart' show parse;
import 'package:html/dom.dart';
main() {
final url = 'http://comic-walker.com/';
getHtml(url).then((document) {
// page title