Skip to content

Instantly share code, notes, and snippets.

View VigneshChennai's full-sized avatar

Vigneshwaran P VigneshChennai

View GitHub Profile
@VigneshChennai
VigneshChennai / variance.rs
Last active July 26, 2022 15:40
Covariant and Invariant - Rust Example
struct CovariantExample<'a, T> {
a: &'a T
}
struct InvariantExample<'a, T> {
a: &'a mut T
}
fn covarient() {
@VigneshChennai
VigneshChennai / drop_check_unsoundness.rs
Created November 2, 2020 04:13
Rust: Example of how "not owning a generic T" can allow unsound usage
#![feature(dropck_eyepatch)]
use std::alloc::Layout;
use std::ops::{Deref, DerefMut};
// use std::marker::PhantomData;
struct InHeap<T: Sized> {
ptr: *const T,
//_m: PhantomData<T> // Using PhantomData will prevent "unsound usage"
}
@VigneshChennai
VigneshChennai / integrate-opengapps.sh
Created September 2, 2020 12:46
opengapps integration script for android-x86
#!/bin/bash
prog=$(basename $0)
if [ ! -f build/envsetup.sh ]; then
echo ${prog}: Please cd to the directory you ran \'repo init\' in.
exit 1
fi
source build/envsetup.sh
@VigneshChennai
VigneshChennai / tailcsv.py
Last active September 24, 2018 09:27
Python script to tail (like the posix tail command) a csv file which has records which span multiple lines
#!/usr/bin/env python
# tailcsv.py is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# tailcsv.py is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@VigneshChennai
VigneshChennai / controlled_recursion.py
Created November 17, 2016 06:33
Controlled recursion in python
def controlled_recursion(default=None, depth=0):
def entangle(f):
lock = threading.Lock()
f.call_counts = {}
def increment():
with lock:
call_count = f.call_counts.get(threading.currentThread().ident, 0)
call_count += 1
f.call_counts[threading.currentThread().ident] = call_count
@VigneshChennai
VigneshChennai / PyPrintLogger
Created February 19, 2015 15:06
PyPrintLogger - A python module to use in built print function as logger
#!/usr/bin/env python
# PyPrintLogger is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# PyPrintLogger is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@VigneshChennai
VigneshChennai / PyDaemonize
Last active August 29, 2015 14:15
PyDaemonize - A python function to daemonize a python application
#!/usr/bin/env python
# PyDaemonize is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# PyDaemonize is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@VigneshChennai
VigneshChennai / PyArgumentParser
Created January 28, 2015 12:35
A python argument parser
#!/usr/bin/env python
# This file is part of PyArgumentParser.
# PyArgumentParser is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# PyArgumentParser is distributed in the hope that it will be useful,
@VigneshChennai
VigneshChennai / gist:5c6ec6344fc28c68b9a9
Created January 11, 2015 05:04
gnome-builder support log
[runtime.host]
hostname = "Optiplex-3020"
username = "vignesh"
codeset = "UTF-8"
cpus = 4
cache_dir = "/home/vignesh/.cache"
data_dir = "/home/vignesh/.local/share"
config_dir = "/home/vignesh/.config"
runtime_dir = "/run/user/1000"
home_dir = "/home/vignesh"