Skip to content

Instantly share code, notes, and snippets.

View thewickedaxe's full-sized avatar

Srinivas Suresh Kumar thewickedaxe

View GitHub Profile
@thewickedaxe
thewickedaxe / argparse-dynamic.py
Created August 2, 2017 16:50
Dynamic args in argparse
parser=argparse.ArgumentParser()
parser.add_argument('-k','--kwarg',nargs=3,action='append')
args=parser.parse_args('-k mass 100 inf -k spin 0.5 1.0'.split())
Namespace(kwarg=[['mass', '100', 'inf'], ['spin', '0.5', '1.0']])
they could be converted to a dictionary with an expression like:
vargs={key:(float(v0),float(v1)) for key,v0,v1 in args.kwarg}
which could be passed to your function as:
@thewickedaxe
thewickedaxe / autoviv.py
Created July 28, 2017 23:00
Auto Vivification in Python
from collections import defaultdict
tree = lambda: defaultdict(tree)
t = tree()
t[1][2][3] = 4
t[1][3][3] = 5
t[1][2]['test'] = 6
@thewickedaxe
thewickedaxe / memeater.py
Created July 7, 2017 17:25
Script to eat memory on python
import argparse
import time
GB = 1024 * 1024 * 1024
def parse_cmd_args():
"""
Parses command line args
"""
parser = argparse.ArgumentParser(description='Memory Eating utility for python')
@thewickedaxe
thewickedaxe / prot_test.cpp
Created March 13, 2017 01:21
Protected memeber Function
class A
{
private:
int _privInt = 0;
int privFunc(){return 0;}
virtual int privVirtFunc(){return 0;}
protected:
int _protInt = 0;
int protFunc(){return 0;}
public:
@thewickedaxe
thewickedaxe / gist:c59a8ec07f53bc4a4e779f2e7e50940b
Last active March 12, 2017 23:03
VS code multi arg tasks default file
{
"version": "0.1.0",
"tasks": [
{
"taskName": "Build",
"command": "make",
"args": ["-B"],
"isShellCommand": true,
"isBuildCommand": true
}
@thewickedaxe
thewickedaxe / correct_comprataor.cpp
Created February 14, 2017 08:08
Correct Comparator
bool areEqualRel(float a, float b, float epsilon) {
return (fabs(a - b) <= epsilon * std::max(fabs(a), fabs(b)));
}
struct PointCompare
{
bool operator() (const Point3D< float >& lhs, const Point3D< float >& rhs) const
{
if (lhs[0] < rhs[0]) {
return true;
@thewickedaxe
thewickedaxe / revlist.cpp
Created October 11, 2016 02:08
Reversing a linked list with 1 pointer
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
struct node {
int key;
node* next;