Skip to content

Instantly share code, notes, and snippets.

Ashwin Nanjappa ashwin

Block or report user

Report or block ashwin

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
ashwin / virtual_function_example.cpp
Created Jun 13, 2017
Example program of virtual function in C++
View virtual_function_example.cpp
#include <iostream>
struct A
virtual void do_something() {}
virtual void do_something2() { std::cerr << "In A\n"; }
struct B : public A
ashwin / aligned_malloc.cpp
Last active Oct 1, 2019
Aligned memory allocation
View aligned_malloc.cpp
// Assume we need 32-byte alignment for AVX instructions
#define ALIGN 32
void *aligned_malloc(int size)
// We require whatever user asked for PLUS space for a pointer
// PLUS space to align pointer as per alignment requirement
void *mem = malloc(size + sizeof(void*) + (ALIGN - 1));
// Location that we will return to user
>>> isinstance(True, int)
>>> isinstance(True, float)
>>> isinstance(3, int)
>>> isinstance([1,2,3], list)
>>> isinstance("aa", str)
ashwin /
Created Feb 27, 2017
How to convert Python dict to class object with fields
>>> from collections import namedtuple
>>> d = {"name": "joe", "age": 20}
>>> d
{'age': 20, 'name': 'joe'}
>>> d_named = namedtuple("Employee", d.keys())(*d.values())
>>> d_named
Employee(name='joe', age=20)
ashwin / ref_to_ptr.cpp
Created Dec 28, 2016
Example showing difference between pointer-to-pointer and reference-to-pointer in C++
View ref_to_ptr.cpp
// Example that shows difference between pointer-to-pointer
// and reference-to-pointer.
#include <cstdio>
void func_ptr(int **x)
*x = new int;
**x = 100;
ashwin / virtual_base_dtor.cpp
Last active Dec 28, 2016
Example showing why C++ base class destructor should be virtual
View virtual_base_dtor.cpp
// Example to show why base class destructor should be virtual.
// If ~A is not virtual below, you will notice that B's destructor
// is not called and B's Foo object is not freed. Memory leak!
// Change ~A to virtual and Foo is freed at end of scope correctly.
#include <iostream>
#include <memory>
using namespace std;
ashwin / override_final.cpp
Created Nov 21, 2016
Example of using override and final in C++
View override_final.cpp
#include <iostream>
// Virtual method declarations
struct A
virtual void Foo() const;
struct B : public A
ashwin / Doxyfile_cpp_cuda
Last active Aug 27, 2019
Doxyfile I use for C++ and CUDA code
View Doxyfile_cpp_cuda
# Doxyfile 1.8.6
# This file describes the settings to be used by the documentation system
# doxygen ( for a project.
# All text after a double hash (##) is considered a comment and is placed in
# front of the TAG it is preceding.
# All text after a single hash (#) is considered a comment and will be ignored.
# The format is:
ashwin / default-ignore-list
Created Feb 1, 2016
The default ignore list of Stow
View default-ignore-list
# Comments and blank lines are allowed.
\.\#.+ # CVS conflict files / emacs lock files
ashwin / uni_init.cpp
Last active Sep 11, 2018
Examples of uniform initialization syntax in C++
View uni_init.cpp
#include <iostream>
#include <stack>
#include <unordered_set>
#include <vector>
class Point
int x;
int y;
You can’t perform that action at this time.