Skip to content

Instantly share code, notes, and snippets.

View sharmaeklavya2's full-sized avatar
📚
Not coding actively anymore. Doing math instead.

Eklavya Sharma sharmaeklavya2

📚
Not coding actively anymore. Doing math instead.
View GitHub Profile
#!/usr/bin/env python3
"Takes a Jinja2 template file and a JSON context file as input. Returns rendered output."
import json
import argparse
import jinja2
def render(template_path, context_path, output_path):
with open(template_path) as tfp:
@sharmaeklavya2
sharmaeklavya2 / bp1.context.json
Last active March 2, 2021 08:09
SVG BP1 animation
{
"W": 640,
"H": 480,
"binW": 200,
"binH": 120,
"items": [
{"size": 0.5, "cumSize": 0.0, "packBin": 0, "packPos": 0.0},
{"size": 0.4, "cumSize": 0.5, "packBin": 1, "packPos": 0.0},
{"size": 0.3, "cumSize": 0.9, "packBin": 0, "packPos": 0.5},
{"size": 0.3, "cumSize": 1.2, "packBin": 1, "packPos": 0.4},
@sharmaeklavya2
sharmaeklavya2 / download-socg-lipics.py
Created November 19, 2020 08:51
Download the files needed to compile a LaTeX paper for SoCG21
#!/usr/bin/env python3
"""Downloads all the files necessary to compile a LaTeX paper
as per the instructions of SOCG21."""
import sys
import os
from urllib.request import urlopen
from zipfile import ZipFile
@sharmaeklavya2
sharmaeklavya2 / check_matroid.py
Created November 10, 2020 16:05
Check if a set family is a matroid
#!/usr/bin/env python3
import ast
def check_matroid(indsets):
if () not in indsets:
return ()
# check hereditary
@sharmaeklavya2
sharmaeklavya2 / up_it_up.py
Created February 20, 2020 12:40
Brute-force solution to up-it-up (game by CCL, IITGN)
import argparse
import sys
from collections import deque
BLOCK_TRN = {
('u', 'f'): 'f',
('u', 'b'): 'b',
('u', 'l'): 'l',
('u', 'r'): 'r',
@sharmaeklavya2
sharmaeklavya2 / polyglot.c
Created December 10, 2019 18:11
Program which is valid in both C and python
#include <stdio.h> /*
print("python"); """
#define ABC */
int main() {
puts("c");
return 0;
}
/* """
@sharmaeklavya2
sharmaeklavya2 / cga_sym.py
Created November 2, 2019 14:11
Solving linear equations using conjugate gradient descent with exact arithmetic
import sys
import argparse
from sympy import Matrix, ImmutableMatrix, Rational
def to_print_type(a):
return a
def cga(Q, b, x, n, err_thresh=0, opt=None):
@sharmaeklavya2
sharmaeklavya2 / segtree.cpp
Last active January 27, 2024 09:13
Generic SegTree
// See codechef FLIPCOIN for an example
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <vector>
/*
Output of segment tree range queries are modelled as elements of a monoid.
Updates on the segment tree are functions on the monoid.
@sharmaeklavya2
sharmaeklavya2 / phrase_anagram_checker.py
Created June 13, 2019 18:54
phrase anagram checker
#!/usr/bin/env python3
"""Takes multiple lines as input and checks if they are anagrams."""
import re
import hashlib
import argparse
def normalize(s):

JavaScript object hierarchy

This document aims to explain what various attributes like constructor, prototype and __proto__ point to and what happens when new objects are created.

There are several ways of creating new objects:

  • o = {'one': 1, 'two': 2};
  • function f() {return 'three';}