Skip to content

Instantly share code, notes, and snippets.

View richwednesday's full-sized avatar
😀
exploring

Joseph Iwok richwednesday

😀
exploring
View GitHub Profile
@richwednesday
richwednesday / String drills
Created December 7, 2016 03:35
Links to works on JavaScript String Drills on Thinkful Front end web dev course
http://jsbin.com/cipaxex/edit?js,console
https://jsbin.com/sideniv/edit?js,console
https://jsbin.com/gasarod/edit?js,console
@richwednesday
richwednesday / index.js
Last active September 24, 2024 07:35
Hangman Game you can play from the command line written in Node js
let targetWord = '';
let dashes = '';
let dArray = [];
let failCount = 0;
const categories = {
clubs: ['Manchester United', 'Barcelona', 'Real Madrid', 'Bayern Munich',
'Manchester City', 'Arsenal', 'Chelsea', 'Liverpool', 'Juventus', 'Tottenham Hotspur',
'Borussia Dortmund', 'Atletico Madrid', 'Inter Milan', 'West Ham United', 'Roma',
'Napoli', 'Everton', 'Newcastle United'],
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();
}
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");
@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
});
@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)
},
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* sudoku.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jiwok <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/20 20:00:06 by jiwok #+# #+# */
/* Updated: 2019/07/20 21:18:15 by jiwok ### ########.fr */
/* */
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
}
@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
}
@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);