Skip to content

Instantly share code, notes, and snippets.

@nootanghimire
nootanghimire / phpbf.php
Last active February 14, 2018 17:58
Attempt at writing brainfuck compiler in php
<?php
function compile(string $brainfuck, $debug = false): array
{
$program = [];
$pointer = 0;
$ip = 0;
$prog_length = strlen($brainfuck);
$loopStack = [];
while (true) {
FROM ubuntu:12.04
MAINTAINER [email protected]
# Add Repo for PHP 5.4 Support
RUN echo "deb http://ppa.launchpad.net/ondrej/php5-oldstable/ubuntu precise main " > /etc/apt/sources.list.d/ondrej.list && apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E5267A6C
# Install php-5.4 and build essentials
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get -qqy install \
@nootanghimire
nootanghimire / functions.js
Created May 14, 2016 08:55
A Code Specific to an example to generate permuted block randomization for sampling
function generateRandom(_threshold){
var threshold = _threshold || 0.5;
returnArray = [];
holdArray = [];
for(var i = 1; i<=200; i++) {
holdArray = []; //init
for(var j = 1; j<=6; j++) {
if(Math.random() >= threshold){
if(howmanyInArray(holdArray, "odd") >= 3) {
holdArray.push("even");
@nootanghimire
nootanghimire / steps.md
Created February 18, 2016 15:53
Basic TODOs after a new installation of irssi (if you do not have your old config and scripts lying around)
  1. Download http://scripts.irssi.org/scripts/cap_sasl.pl and paste it to ~/.irssi/scripts/
  2. Symlink and add to autorun $ mkdir autorun; cd autorun; ln -s ../cap_sasl.pl
  3. Open up irssi $ irssi
  4. Run the following commands
  5. /script load autorun/cap_sasl.pl
  6. /sasl set <chatnet> <nick> <password> plain and /sasl save
  7. You can replace plain with external, ECDSA-NIST256P-CHALLENGE, or DH-BLOWFISH . See https://freenode.net/sasl/sasl-irssi.shtml
  8. There are list of common servers already configed. List includes Freenode, OFTC, etc.. See ~/.irssi/config for the list
  9. Edit ~/.irssi/config to add autoconnect = "yes" inside servers array after port = "6667" :) (in a different tab?)
  10. Add channels to autoconnect. Sample: /channel add -auto #channel ChatNet . For more information about this, see https://irssi.org/documentation/startup/#server-and-channel-automation . This also contains more advanced details about botmasks and botcmds.
var url = "https://mozilla-nepal.org/translation-helper-pootle/translate.php?string=";
document.onclick = function (e) {
var elem, evt = e ? e:event;
if (evt.srcElement) elem = evt.srcElement;
else if (evt.target) elem = evt.target;
if(elem.nodeName == "INPUT" || elem.nodeName == "TEXTAREA") {
------------------------------------------------------------
~/codes/foss-np/anubad(branch:master) » git pull 0 - cparch@cparch
Already up-to-date.
------------------------------------------------------------
~/codes/foss-np/anubad(branch:master) » ./configure 0 - cparch@cparch
./src/mysettings.conf
--2015-10-28 19:55:47-- https://github.com/foss-np/np-l10n-glossary/archive/current.tar.gz
Resolving github.com (github.com)... 192.30.252.130
Connecting to github.com (github.com)|192.30.252.130|:443... connected.
HTTP request sent, awaiting response... 302 Found
exports.findResultsByFreeText = function(req, res, next, freeText) {
//TODO: Check if request contains facet params, and filter accordingly
req.results = []; //Array
getListOfTeams(req.user.username).then(function(results) {
promise_map(function(result){
//console.log("a");
elasticsearch_client.search({
index: result.teamUnique + "_team",
type: result.username,
body: {
@nootanghimire
nootanghimire / promises-reading-list.md
Created October 21, 2015 18:23 — forked from joepie91/promises-reading-list.md
Promises (Bluebird) reading list

Promises reading list

This is a list of examples and articles, in roughly the order you should follow them, to show and explain how promises work and why you should use them. I'll probably add more things to this list over time.

This list primarily focuses on Bluebird, but the basic functionality should also work in ES6 Promises, and some examples are included on how to replicate Bluebird functionality with ES6 promises. You should still use Bluebird where possible, though - they are faster, less error-prone, and have more utilities.

I'm available for tutoring and code review :)

You may reuse all gists for any purpose under the WTFPL / CC0 (whichever you prefer).

@nootanghimire
nootanghimire / Makefile
Last active August 29, 2015 14:07
MIT 6.873 Computer Graphics - Assignment 0 - Load .OBJ image models in opengl
INCFLAGS = -I /usr/include/GL
INCFLAGS += -I /mit/6.837/public/include/vecmath
LINKFLAGS = -lglut -lGL -lGLU
LINKFLAGS += -L /mit/6.837/public/lib -lvecmath
CFLAGS = -O2
CC = g++
SRCS = main.cpp
OBJS = $(SRCS:.cpp=.o)
@nootanghimire
nootanghimire / graph_min_span_tree.py
Last active August 29, 2015 14:05
Graphs in Python
#!/usr/bin/python
from __future__ import print_function
class Vertex:
def __init__(self, label, value=None):
self.label = label