Skip to content

Instantly share code, notes, and snippets.

<?php
class Template {
public static $vars = array();
public static function bind($key, $value) {
self::$vars[$key] = $value;
}
public static function render($name) {
$contents = file_get_contents($name.".php");
// A simple text editor implemented in Java using JFrame
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.io.BufferedWriter;
import java.io.File;
# TODO: shuffle dataset before gradient descent?
# import random libraries
from random import random, shuffle
# this function scales down from [0,1) to [0,0.16) in order to reduce the amount of "wobble"
def rand():
return random()/6
# main regressor class
@ashwinreddy
ashwinreddy / spotify-cover.py
Created January 21, 2017 22:02
Retrieves Spotify album image
import urllib2
import urllib
import json
music_type = raw_input("Track or Album? [t/a] ")
if music_type.startswith('t'):
music_type = 0
elif music_type.startswith('a'):
music_type = 1
#!/usr/bin/env bash
function disp() {
printf "\033[1;31m";
printf "$1";
printf "\033[0m\n";
}
# Atom installation script
# By Ashwin Reddy
@ashwinreddy
ashwinreddy / coordinate_systems
Created September 13, 2017 01:43
Coordinate Systems
## Cylindrical
![Imgur](https://i.imgur.com/hMRNeAw.png)
Essentially extends polar to include a $z$-component.
$(r,\theta,z)$
$$
r = x\cos\theta \\\
r = y\sin\theta \\\
z = z
import itertools
import numpy as np
class BanzhafPower(object):
def __init__(self, voting_system):
self.voting_system = voting_system
self.generate_coalitions()
self.compute_critical_count()
def generate_coalitions(self):
class HuffmanTree(object):
def __init__(self, left, right):
self.left = left
self.right = right
def encode(self, symbol):
for branch, instruction in ((self.left, "0"), (self.right, "1")):
if type(branch) is HuffmanTree:
if branch.encode(symbol):
@ashwinreddy
ashwinreddy / Spotify.lua
Created February 13, 2019 04:19
Hammerspoon configuration to update Mac wallpaper background to the currently playing Spotify track's album artwork
hs.loadSpoon("ReloadConfiguration")
spoon.ReloadConfiguration:start()
function resetImage()
screen = hs.screen.mainScreen()
screen:desktopImageURL("file:///Users/areddy/Pictures/original_8ee2e1707ce7198a75211221f99e6c2d.jpeg")
end
function updateImage()
;; -*- mode: emacs-lisp -*-
;; This file is loaded by Spacemacs at startup.
;; It must be stored in your home directory.
;; This is Ashwin Reddy's custom spacemacs config
(defun dotspacemacs/layers ()
"Configuration Layers declaration.
You should not put any user code in this function besides modifying the variable
values."
(setq-default