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
ashwin / .Xresources
Created Jul 27, 2017
My ~/.Xresources config for xterm
View .Xresources
! =============================================================================
! XTerm settings
! =============================================================================
! Use white-on-black colors
XTerm.vt100.reverseVideo: true
UXTerm.vt100.reverseVideo: true
! XTerm already has 256 colors support
! We ask it to set the correct $TERM
@ashwin
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
@ashwin
ashwin / type_tree.py
Created Dec 11, 2017
Print type hierarchy tree
View type_tree.py
#!/usr/bin/env python3
"""Print hierarchy of types present in Python."""
import argparse
import sys
def is_builtin(t):
"""Check if type is builtin."""
builtin_s = "__builtin__" if sys.version_info.major <= 2 else "builtins"
@ashwin
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 (www.doxygen.org) 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
ashwin / dict_to_namedtuple.py
Created Feb 27, 2017
How to convert Python dict to class object with fields
View dict_to_namedtuple.py
>>> 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)
>>> d_named.name
'joe'
@ashwin
ashwin / gist:3269777
Created Aug 6, 2012
Delete pages from DjVu document
View gist:3269777
# Delete page 170 from foo.djvu
djvm -d foo.djvu 170
# Delete pages 170-174 from foo.djvu
for ( $i = 0; $i -lt 5; $i++ ) { djvm -d foo.djvu 170 }
@ashwin
ashwin / build-cuda.cmake
Last active Jul 30, 2019
Sample CMakeLists.txt file to build a CUDA program
View build-cuda.cmake
### CMakeLists.txt for CUDA
cmake_minimum_required(VERSION 2.8)
find_package(CUDA QUIET REQUIRED)
# Pass options to NVCC
set(
CUDA_NVCC_FLAGS
${CUDA_NVCC_FLAGS};
-O3 -gencode arch=compute_22,code=sm_22
@ashwin
ashwin / git-rename-remote-branch
Created Oct 12, 2017
Git script to rename remote branch
View git-rename-remote-branch
#!/bin/sh
# From: https://github.com/sschuberth/dev-scripts/
if [ $# -ne 3 ]; then
echo "Rationale : Rename a branch on the server without checking it out."
echo "Usage : $(basename $0) <remote> <old name> <new name>"
echo "Example : $(basename $0) origin master release"
exit 1
fi
@ashwin
ashwin / getopt_long_example.cpp
Last active Jul 26, 2019
How to parse options in C++ using getopt_long
View getopt_long_example.cpp
#include <getopt.h>
#include <iostream>
int num = -1;
bool is_beep = false;
float sigma = 2.034;
std::string write_file = "default_file.txt";
void PrintHelp()
{
@ashwin
ashwin / fileopendialog.py
Created Feb 25, 2014
File Open dialog in Python to read in a file path
View fileopendialog.py
import Tkinter
import tkFileDialog
def main():
Tkinter.Tk().withdraw() # Close the root window
in_path = tkFileDialog.askopenfilename()
print in_path
if __name__ == "__main__":
You can’t perform that action at this time.