Skip to content

Instantly share code, notes, and snippets.

View chaiwa-berian's full-sized avatar

Berian chaiwa-berian

View GitHub Profile
@chaiwa-berian
chaiwa-berian / PRISMA_ERROR_CODES.ts
Last active June 16, 2022 03:34
A lookup constant object for Prisma Error Codes, with brief messages. Handy if you wanna send cleaner messages back to the client for better UI/UX!
const PRISMA_ERROR_CODES: Record<string, string> = {
P1000: "Authentication failed against database server.",
P1001: "Can't reach database server.",
P1002: "The database server was reached but timed out.",
P1003: "Database does not exist at file_path.",
P1008: "Operations timed out.",
@chaiwa-berian
chaiwa-berian / expression.js
Last active November 15, 2020 14:11
OpenFn devtools testing
get(state.configuration.dataSourceUrl,{
query: {userId: 1},
headers: state.configuration.headers
},
function(state){
var posts = state.data;
return posts.reduce(function(acc, item){
item.tag = `${state.configuration.tags.testing}`;
return acc.then(
post(state.configuration.inboxUrl,{body: item, headers: state.configuration.headers})
@chaiwa-berian
chaiwa-berian / Step 1: Create API User.MD
Last active April 8, 2024 12:02
Testing MTN MoMo Collection API in Sandbox using Postman

A. Checklist

  • To create an API User, you need the following things in place: X-Reference-Id and Ocp-Apim-Subscription-Key

1. X-Reference-Id

  • This is used as User ID since the Sandbox is a Mock Environment so we kinda create our own ids and send them over to the sandbox so it can uniquely identify the user
  • Get the value for this here: https://www.uuidgenerator.net/api/version4
  • Remember to keep this safely as we will use it when configuring our POST request
  • Lets say you have your X-Reference-Id as: 9f92971b-cd2e-4feb-9053-0b14d53ac4f5

2. Ocp-Apim-Subscription-Key

  • Get this from the Primary or Secondary Key of your Collections | Enable remote collection of bills, fees or taxes subscription.
@chaiwa-berian
chaiwa-berian / db_initialization.js
Last active October 23, 2019 12:50
Initializing tables with default records via nodejs and mongoose
//refs to models
let User = require('../../app/common/models/user_models/user_model');
let UserRolePermission = require('../../app/common/models/user_models/user_role_permission_model');
let UserRole = require('../../app/common/models/user_models/user_role_model');
//=========================work starts here==================
let users_initialized;
let permissions_initialized;
let roles_initialized;
async function usersInitialized() {
@chaiwa-berian
chaiwa-berian / app_router.js
Created June 28, 2019 20:35
MVC+Express+MySQL+NodeJs
module.exports = function(app, connection){
//Routing requests for /books
app.use('/books', require('./books.router')(connection));
//List any other potential routes below
}
@chaiwa-berian
chaiwa-berian / ApiResponse.java
Last active May 16, 2019 14:42 — forked from AkshayChordiya/ApiResponse.java
LiveData adapter for Retrofit
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.util.ArrayMap;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@chaiwa-berian
chaiwa-berian / Gitignore the already commited node_modules.txt
Created September 2, 2018 10:42
Gitignore the already commited node_modules
#add 'node_modules' to .gitignore file
git rm -r --cached node_modules
git commit -m 'Remove the now ignored directory node_modules'
git push origin master
@chaiwa-berian
chaiwa-berian / read_big_file_without_using_nodejs_streams.js
Created August 20, 2018 19:04
Read a big file without using streams
const fs = require('fs');
const server = require('http').createServer();
server.on('request', (req, res) => {
fs.readFile('./big.file', (err, data) => {
if (err) throw err;
res.end(data);
});
});
@chaiwa-berian
chaiwa-berian / create_big_file_testing_nodejs_streams.js
Created August 20, 2018 19:02
Create a big file for testing streams
const fs = require('fs');
const file = fs.createWriteStream('./big.file');
for(let i=0; i<= 1e6; i++) {
file.write('Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\n');
}
file.end();
var Writable = require('stream').Writable;
var ws = Writable();
ws._write = function (chunk, enc, next) {
console.dir(chunk);
next();
};
process.stdin.pipe(ws);