Skip to content

Instantly share code, notes, and snippets.

import React from 'react';
class Card extends React.Component {
constructor() {
super();
this.state = {
colors: ['blue-grey', 'red', 'brown' ]
}
}
render() {
@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 / 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 / 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'))
function Token(type, value) {
this.type = type;
this.value = value;
}
function isComma(ch) {
return /,/.test(ch);
}
function isDigit(ch) {
@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",

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 / 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);
}
}
@shalvah
shalvah / twitter-redux-example.js
Last active December 30, 2018 11:35
Basic example of how Redux could be used to manage state in a frontend app like Twitter Lite (mobile.twitter.com)
import { createStore } from 'redux';
// our reducer
const tweets = (state = {tweets: []}, action) => {
switch (action.type) {
// we'll handle only one action: when new tweets arrive
case 'SHOW_NEW_TWEETS':
state.numberOfNewTweets = action.count;
return state.tweets.concat([action.tweets]);
default:
// without event sourcing
function transferMoneyBetweenAccounts(amount, fromAccount, toAccount) {
BankAccount.where({ id: fromAccount.id })
.decrement({ amount });
BankAccount.where({ id: toAccount.id })
.increment({ amount });
}
function makeOnlinePayment(account, amount) {
BankAccount.where({ id: account.id })