Skip to content

Instantly share code, notes, and snippets.

View flockonus's full-sized avatar
🏯

Fabiano flockonus

🏯
View GitHub Profile
/// @dev given a number get a slice of any bits, at certain offset
/// @param _n a number to be sliced
/// @param _nbits how many bits long is the new number
/// @param _offset how many bits to skip
function _sliceNumber(uint256 _n, uint256 _nbits, uint256 _offset) private pure returns (uint256) {
// mask is made by shifting left an offset number of times
uint256 mask = uint256((2**_nbits) - 1) << _offset;
// AND n with mask, and trim to max of _nbits bits
return uint256((_n & mask) >> _offset);
}
@flockonus
flockonus / randomStr.js
Last active March 27, 2018 18:30
Random 8-length string JS
// Really fast way to create 8 bytes random string =~ 1e12 possibilities
Math.round(Math.random() * 1e13).toString(32).substr(-8,8)
const Web3 = require('web3');
const fs = require('fs');
const web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8945'));
web3.BigNumber.config({ EXPONENTIAL_AT: 1000 });
LunarAddress = '0x43fb95c7afa1ac1e721f33c695b2a0a94c7ddab2';
LunarAbi = [{"constant":false,"inputs":[{"name":"enabled","type":"bool"}],"name":"setSubdivisionEnabled","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"id","type":"uint256"},{"name":"metadata","type":"string"},{"name":"forSale","type":"bool"},{"name":"newPrice","type":"uint256"}],"name":"purchase","outputs":[{"name":"","type":"bool"}],"payable":true,"stateMutability":"payable","type":"function"},{"constant":true,"inputs":[],"name":"numPlots","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":fal
@flockonus
flockonus / wait-please.js
Last active September 2, 2017 04:05
async wont wait forEach :(
function performTask(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
// this wont work as intended
async function asyncFn1() {
const someTasks = [1, 2, 3, 4, 5];
let taskSum = 0;
someTasks.forEach(async t => {
await performTask(t);
Few bonus inputs (randomized by rows^(rows-1) moves)

5: {"puzzle":[[2,5,13,11,17],[20,3,-1,12,7],[24,22,9,14,1],[10,15,18,21,4],[16,8,23,6,19]]}
5: {"puzzle":[[2,24,3,18,14],[16,7,8,17,15],[4,13,11,21,1],[12,23,9,6,10],[19,-1,22,5,20]]}

6: {"puzzle":[[29,24,28,34,35,21],[1,7,20,31,22,-1],[18,17,9,25,23,19],[6,30,8,3,32,13],[27,2,15,4,10,26],[5,33,12,14,16,11]]}
6: {"puzzle":[[11,1,7,8,33,4],[3,19,26,9,25,16],[20,23,24,34,32,14],[31,21,35,27,5,-1],[30,6,15,2,29,28],[12,22,17,10,13,18]]}
@flockonus
flockonus / customEmojiCount.js
Last active October 23, 2024 04:12
Count your emojis from Slack usage!
'use strict';
/**
npm i bluebird slack-node
CREATE YOUR TOKEN: https://api.slack.com/docs/oauth-test-tokens?team_id=T024G49EC&action=reissue&sudo=1
npm package: https://www.npmjs.com/package/slack-node
user.list: https://api.slack.com/methods/users.list
server
.register({
// https://www.npmjs.com/package/good
register: Good,
options: {
reporters: [{
reporter: require('good-console'),
events: {
response: '*',
@flockonus
flockonus / 1 list.md
Last active March 29, 2016 23:18
TO LEARN
@flockonus
flockonus / gist:ee26abd6887cc79ec3f0
Created June 5, 2015 19:37
consistency-ui-design-creativity
already have downloaded too
http://www.uxpin.com/consistency-ui-design-creativity.html
@flockonus
flockonus / minimal.js
Last active August 29, 2015 14:20
Express get lost in co() context --WRONG
var express = require('express');
var app = express();
var co = require('co');
function * sleep(){
var p = new Promise(function(w,f){
setTimeout(w,1000,'winning');
});
return yield p;