Skip to content

Instantly share code, notes, and snippets.

View richwednesday's full-sized avatar
😀
exploring

Joseph Iwok richwednesday

😀
exploring
View GitHub Profile
pragma solidity >=0.7.0 <0.9.0;
interface cETH {
// define functions of COMPOUND we'll be using
function mint() external payable; // to deposit to compound
function redeem(uint redeemTokens) external returns (uint); // to withdraw from compound
@richwednesday
richwednesday / fix_stream_price.js
Last active August 16, 2020 20:42
Streaming Price of Bitcoin from FTX> https://docs.ftx.com/#websocket-api
import WebSocket from 'ws';
const ws = new WebSocket('wss://ftx.com/ws/');
let ping;
function open() {
ws.on('open', function open() {
ws.send(JSON.stringify({
op: 'subscribe',
channel: 'ticker',
market: 'BTC-PERP'
@richwednesday
richwednesday / hash.js
Last active May 20, 2020 06:25
hash_frontend_js
async function digestMessage(message) {
const encoder = new TextEncoder();
const data = encoder.encode(message);
const hash = await crypto.subtle.digest('SHA-256', data);
return hash;
}
function toHexString(byteArray) {
return Array.from(byteArray, function(byte) {
return ('0' + (byte & 0xFF).toString(16)).slice(-2);
@richwednesday
richwednesday / chatbot.js
Last active April 29, 2020 08:30
sample code for a simple chat bot
function receiveMessage(id, text)
{
let state = redis.get(id);
if (state === "expecting default selection") processDefaultSelection(id, text)
else if (state == "expecting location") processLocationResponse(id, text)
else if (state === "expecting quantity") processQuantityResponse(id, text)
else sendDefaultMessage(id); // first message from user or user is in no state
}
const request = require('request-promise');
const environment = "staging";
const t_config = {
oauth: {
consumer_key: process.env.TWITTER_CONSUMER_KEY,
consumer_secret: process.env.TWITTER_CONSUMER_SECRET,
token: process.env.TWITTER_ACCESS_TOKEN,
token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET
}
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* sudoku.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jiwok <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/20 20:00:06 by jiwok #+# #+# */
/* Updated: 2019/07/20 21:18:15 by jiwok ### ########.fr */
/* */
@richwednesday
richwednesday / redis.js
Created September 21, 2018 13:27
redis magic
overwrite(id, obj) {
client.del(`${id}-creation`, () => {
client.HMSET(`${id}-creation`, obj)
})
},
update(id, obj) {
client.HMSET(`${id}-creation`, obj)
},
@richwednesday
richwednesday / upload.js
Created December 28, 2017 19:46
Image Upload to S3 From Node.js
const http = require("http");
const https = require("https");
const AWS = require('aws-sdk');
const formidable = require("formidable");
const uuid = require("uuid");
let server = http.createServer(launch);
let s3 = new AWS.S3({
// s3 credentials
});
sanitizePhoneNumber(phone, ext, errh) {
errh = errh || function() {};
if(typeof phone !== "string" && !(phone instanceof String)) {
errh("Phone number should be a string, "+(typeof phone)+" passed.");
return false;
}
if (phone.charAt(0) === "+") phone = phone.substring(1);
if (isNaN(Number(phone))) {
errh ("Phone number contains non-numeric characters");
else if (path === "invites/accept") {
if (!session.uid) {
response.write(sessionErrorMessage);
return response.end();
}
let status = yield db.collection("groups_members").insert({uid: session.uid, groupID: data.groupID, timestamp: new Date()});
if (!status.result.ok) {
response.write('{"status": 500, "message": "Oops! An error occurred while adding you to group. Please try again."}');
return response.end();
}