Skip to content

Instantly share code, notes, and snippets.

View kghose's full-sized avatar
🕉️

Kaushik Ghose kghose

🕉️
View GitHub Profile
@kghose
kghose / main.cpp
Created November 21, 2017 03:44
Exploring inlining of virtual functions
// compile with:
// g++ -O2 --std=c++14 -Rpass=inline main.cpp 2> >(grep "pages_from_the_fire" -A1)
//
#include <iostream>
#include <vector>
class Base {
public:
virtual int pages_from_the_fire() { return ++x; }
@kghose
kghose / chebyshev-runge.py
Created October 26, 2017 16:03
Demonstrates Runge's phenomenon with polynomial fits
"""
Show us how adding more terms to regular polynomials are good at some
functions (sines for example) but fail with others, such as Runge's
function.
Show how chebyshev nodes help.
"""
import numpy as np
import matplotlib.pyplot as plt
@kghose
kghose / copy-operator.cpp
Last active October 18, 2017 02:37
Copies moves and smart pointers
#include <iostream>
#include <unordered_map>
#include "default.hpp"
class Talkative : public TalkativeBase
{
public:
Talkative& operator=(const Talkative& t)
@kghose
kghose / python-objects.ipynb
Created October 2, 2017 20:29
Simple timing test for creation and access of different python objects
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kghose
kghose / touchdebounce.ino
Created September 21, 2017 04:20
Quick experiment to demonstrate touch screen debouncing/smoothing
/*
* Quick experiment to demonstrate touch screen debouncing/smoothing
*/
#include <Elegoo_GFX.h> // Core graphics library
#include <Elegoo_TFTLCD.h> // Hardware-specific library
#include <TouchScreen.h>
#define YP A3 // must be an analog pin, use "An" notation!
#define XM A2 // must be an analog pin, use "An" notation!
@kghose
kghose / wol.sh
Last active August 30, 2019 01:57
Bash script to perform Wake On Lan
# Shows networking with bash (/dev/udp)
# Shows interpreting hex strings as bytes
BCASTIP=${1}
WOLPORT=7
MAGIC="\xff\xff\xff\xff\xff\xff"
MAC=$(echo ${2} | tr ':' ' ')
# Expects mac address to be punctuated by colons ':', transforms
@kghose
kghose / som.py
Created April 30, 2017 03:06
Self organizing map example
"""
Demo code for showing how a Self-Organized Map (Kohonen Map) learns handwritten digit data in an
unsupervised manner.
Data source: https://archive.ics.uci.edu/ml/machine-learning-databases/optdigits/
This code uses 'optdigits.tra'
Each line is a handwritten digit.
The first 64 numbers are gray levels for an 8 x 8 image.
The last number is the digit class.
@kghose
kghose / bayesian-independence.py
Last active April 13, 2017 20:44
Simple simulator to explore conditional independence in Bayesian networks
"""Simple simulator to explore conditional independence in Bayesian networks
Node representation:
Say the node is has two parents named L and K and the probability table is
L | K | p(T)
--------------
F | F | 0.2
F | T | 0.4
@kghose
kghose / horizons.py
Last active March 21, 2017 19:25
A bare minimum script to query the NASA HORIZONS system for positional data
"""
The URL format is documented at http://ssd.jpl.nasa.gov/horizons_batch.cgi
I figured out the template by using the webinterface to make a query I wanted and then
clicking 'batch-file' to see how the batch file commands would look like.
Also see https://github.com/mommermi/callhorizons by Michael Mommert
"""
import urllib.request
import time
@kghose
kghose / gaussian_isosurface.rkt
Created August 10, 2015 19:00
Racket plotting example
#lang racket
;; Visualize a sum of two 3D Gaussians as concentric isosurfaces
;; Note: this example requires Racket 5.2 or later
(require plot)
;; Returns an R x R x R -> R Gaussian function centered at (cx,cy,cz)
(define ((gaussian cx cy cz) x y z)
(exp (- (+ (sqr (- x cx)) (sqr (- y cy)) (sqr (- z cz))))))