Skip to content

Instantly share code, notes, and snippets.

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