Skip to content

Instantly share code, notes, and snippets.

@shalvah
shalvah / rpn-parser.js
Last active October 22, 2018 19:21
Tokenize and convert a math expression from infix to postfix in Javascript
function parse(inp){
var outQueue=[];
var opStack=[];
Array.prototype.peek = function() {
return this.slice(-1)[0];
};
var assoc = {
"^" : "right",
@shalvah
shalvah / ast-parser.js
Last active October 12, 2019 11:11
Tokenize and create an abstract syntax tree from an infix math expression in Javascript
function ASTNode(token, leftChildNode, rightChildNode) {
this.token = token.value;
this.leftChildNode = leftChildNode;
this.rightChildNode = rightChildNode;
}
function parse(inp){
var outStack=[];
var opStack=[];
function Token(type, value) {
this.type = type;
this.value = value;
}
function isComma(ch) {
return /,/.test(ch);
}
function isDigit(ch) {
import React from 'react';
class Card extends React.Component {
constructor() {
super();
this.state = {
colors: ['blue-grey', 'red', 'brown' ]
}
}
render() {
@shalvah
shalvah / models-post.js
Last active February 14, 2018 08:03
Twitter-Realtime-Likes
let mongoose = require('mongoose');
let Post = mongoose.model('Post', {
text: String,
posted_at: Date,
likes_count: Number,
author: String
});
module.exports = Post;
@shalvah
shalvah / bin-seed.js
Created February 14, 2018 08:03
Twitter-Realtime-Likes
#!/usr/bin/env node
let faker = require('faker');
let Post = require('../models/post');
// connect to MongoDB
require('mongoose').connect('mongodb://localhost/poster');
// remove all data from the collection first
Post.remove({})
@shalvah
shalvah / 01-script.ps1
Created February 16, 2018 22:12
Make PowerShell less like shit and more like Zsh!
# run this command as administrator in PowerShell
# this installs the 'Oh-My-Posh' module (https://github.com/pecigonzalo/Oh-My-Posh)
iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/pecigonzalo/Oh-My-Posh/master/install.ps1'))

Why use this?

Supposing you're building an app (for instance, a voting app), and you want to restrict it to UNN students. Simply ask them to login with their UNN Portal details, and pass them to this API to verify their identity. (Please do not store those credentials 🙏).

How to Use

There's only one endpoint: https://unn-api.herokuapp.com/students/auth

Make a POST request with the following parameters (form-data or application/json content types acceptable)

  • username: The student s unnportal.unn.edu.ng username. Example: 2013/123456
  • password: The student s unnportal.unn.edu.ng password
@shalvah
shalvah / throttle.js
Last active October 24, 2019 09:03
Implementation of throttle functionality in JavaScript
function throttle(f, t) {
return function (args) {
let previousCall = this.lastCall;
this.lastCall = Date.now();
if (previousCall === undefined // function is being called for the first time
|| (this.lastCall - previousCall) > t) { // throttle time has elapsed
f(args);
}
}
}
@shalvah
shalvah / debounce.js
Last active December 22, 2018 09:55
Implementation of debounce functionality in JavaScript
function debounce(f, t) {
return function (args) {
let previousCall = this.lastCall;
this.lastCall = Date.now();
if (previousCall && ((this.lastCall - previousCall) <= t)) {
clearTimeout(this.lastCallTimer);
}
this.lastCallTimer = setTimeout(() => f(args), t);
}
}