Skip to content

Instantly share code, notes, and snippets.

View AbhinavMadahar's full-sized avatar

Abhinav Madahar AbhinavMadahar

View GitHub Profile
@AbhinavMadahar
AbhinavMadahar / Web-Sockets.md
Last active August 29, 2015 14:18
A Very Simple Tutorial on Socket.io

Chatte

This is a simple chat server that adds a new message to all other users' view without needed a page refresh, and all automatically.

It uses the following frameworks:

  • node.js allows us to run JavaScript on the backend
  • express.js makes routing and other basic backend tasks easy
  • socket.io uses Web sockets to share data between the client and server
@AbhinavMadahar
AbhinavMadahar / line.c
Last active August 29, 2015 14:27
Follows a line
#pragma config(Sensor, in1, baseLightSensor, sensorLineFollower)
#pragma config(Sensor, dgtl1, senseDistance, sensorSONAR_cm)
#pragma config(Motor, port6, backLeftMotor, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port7, frontLeftMotor, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port8, frontRightMotor, tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor, port9, backRightMotor, tmotorVex393_MC29, openLoop, reversed)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
#define not !
@AbhinavMadahar
AbhinavMadahar / gpa.md
Last active September 14, 2015 19:08
GPA Ranking in MHS

GPA Ranking: a Simple Proof

Millburn High School does not officially give out class ranks, so you can't truly know if you're in the top 10% or whatever of your grade. That said, it's not too difficult to find this out based on some simple mathematics, although the answer may not be very accurate.

Before I show the proof itself, I want to tell you something: do NOT get caught up in this proof. I am a high schooler just like you, and I have no real mathematical background- I just really like making proofs as a fun pastime. Your worth as a student and human being is not calculatable as a single number. Colleges care about more than just your class rank, so don't get too depressed if you have a subpar class rank. It's just not fun to worry, and worrying about a problem is one of the best ways to avoid having it fixed- I would know. You are NOT your class rank. As Matthew McConaughey said in Interstellar,

It takes two numbers to measure your own ass, bu

var Horseman = require('node-horseman');
var request = require("request");
var horseman = new Horseman();
var timesHit = 0;
var title = "Shrek";
var url = "https://en.wikiquote.org/w/api.php?action=parse&page=" + title + "&format=json"
request(url, function(error, responseCode, body) {

Stalk vibrates when your stocks fall too fast

# import modules needed to send emails
import smtplib
from getpass import getpass
# sends a message to the recipient_email
def send(recipient_email, message):
if not ("@" in recipient_email):
raise Exception("Must have an @ in an email address")
try:
#!/usr/local/bin/python3
# can run a regresion on a set of points
from collections import namedtuple
from random import random, choice
identity = lambda x: x
average = lambda values, key=identity: sum(key(value) for value in values) / len(values)
median = lambda values, key=identity: sorted(values, key=key)[len(values) // 2] # close enough
// Array with all gpas
const gradeNodes = [document.getElementById('grade1')];
const grades = [];
// Create click event listeners for each gpa
gradeNodes.forEach((gradeNode, i) => {
gradeNode.addEventListener("click", () => {
gradeNodes[i].innerHTML = `<input value="${grades[i]}" id="${i}" />`
});
});
@AbhinavMadahar
AbhinavMadahar / regress.py
Last active February 5, 2017 03:33
A simple Regression AI
from collections import namedtuple
Point = namedtuple("Point", ["x", "y"]) # Point(1, 2).x == 1 and Point(1, 2).y == 2
mean = lambda values: sum(values) / len(values)
class Regression(object):
def __init__(self, points):
self.slope = 0 # we'll use gradient descent to find this
self.point = Point(0, 0) # we'll use that stat fact to recalculate this
self.learn_from_data_set(points)
import numpy as np
from random import shuffle
from math import sqrt
sigmoid = lambda z: 1 / (1 + np.exp(-z))
sigmoidprime = lambda z: sigmoid(z) * (1 - sigmoid(z)) # derivate of sigmoid function
def chunk(array, n):
chunks = []
for i in xrange(0, len(array), n):