Skip to content

Instantly share code, notes, and snippets.

View karthick18's full-sized avatar

A R Karthick karthick18

View GitHub Profile
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
struct hash_struct {
struct hash_struct **pprev;
struct hash_struct *next;
};
@karthick18
karthick18 / anagram_group.go
Created March 20, 2024 03:05
Anagram group
package main
import (
"fmt"
"strings"
)
func frequencyHash(word string) string {
frequencyTable := [26]int{}
for _, b := range word {
ascii := int(b)
@karthick18
karthick18 / evaluate.go
Created October 19, 2022 03:32
Leet code string decode problems
package main
import (
"bytes"
"container/list"
"fmt"
"strconv"
"strings"
)
@karthick18
karthick18 / networkx_test.py
Created April 19, 2022 21:05
create 3 switch with 3 hosts config with networkx
#!/usr/bin/env python3
import collections
import networkx
class KindPort(object):
delimiter = "/"
def __init__(self, kind, name, port):
self.kind = kind
self.name = name
@karthick18
karthick18 / vmsplice.c
Created April 13, 2022 19:09
Use splice with vmsplice to move user space buffers to output file
/*
* An example using vmsplice to move user space buffers to pipe before using
* splice syscall which avoids copying to/from user space buffers to kernel space
* and uses the pipe buffers allocated in kernel space as an intermediate to directly xfer from one file to another
*
* gcc -o splice splice.c -g
*/
#define _GNU_SOURCE
#include <stdio.h>
@karthick18
karthick18 / features_and_targets.py
Created November 28, 2018 01:38
Determine features and targets to use for your model using pearson correlation coefficient
def get_features_targets(df, target_correlation_map,
num_features = 2, correlation_method = 'pearson', correlation_barrier = 0.6):
from itertools import combinations
targets = list(df.columns.values)
target_map = {}
#construct a target map using the correlation matrix
for features in combinations(targets, num_features + 1):
#target is first one, remaining are feature combinations
target = features[0]
if target not in target_map:
@karthick18
karthick18 / jump-steps.py
Created June 27, 2017 23:10
Find minimum number of jumps to end of list that can also include negative numbers
# You are given a list of numbers and a starting position.
# Your goal is to find a sequence of jumps from the starting position to the end of the list.
# A valid jump at any position must be between zero and the value at that position in the list, i.e. list[pos], inclusive.
# You must return a list of valid jumps in sequence that lead to the end of the list, or null if no such sequence exists.
# The list can have negative numbers as well that needs to be handled
# The goal is to find minimum number of jumps to reach the end of the list that can also include negative numbers.
import sys
from collections import defaultdict
@karthick18
karthick18 / nanotcplistener.go
Created July 13, 2016 23:53
nanosec tcp proxy server with verification
package main
import (
"github.com/karthick18/nanoclient/nanoproxy/nanotcpproxy"
"github.com/karthick18/nanoclient/nanoproxy/virtualconn"
"net"
"time"
"fmt"
"log"
)
@karthick18
karthick18 / Makefile
Created May 22, 2013 00:58
Hook mmap
## LD_PRELOAD=$PATH/libhookmmap.so $PROG
CC := gcc
SRCS := hook_mmap.c
OBJS := $(SRCS:%.c=%.o)
TARGETS = libhookmmap.so
DEBUG_FLAGS = -g
CFLAGS = -Wall -fPIC -shared
LD_LIBS = -ldl
@karthick18
karthick18 / memcp.c
Last active October 20, 2022 16:48
A test case for overlapping memcpy which is unsafe as glibc resorts to a downward direction memcpy for anything >200 bytes (actually around 222 bytes) Strange as it makes no sense since it ends up impacting apps which don't use memmove for such cases and wasting debugging cycles on obscure data corruption bugs.
/*
* Test glibc overlapping memcpy.
* glibc resorts to a downward direction memcpy for anything exceeding ~200 bytes.
* No clue for the so-called optimization that breaks apps resorting to memcpy
* for overlapping boundaries instead of using memmove.
* This is only specific to x86_64/64 bit as for 32 bits, it always uses a forward memcpy.
*
* Try this --
* gcc -o memcp memcp.c -DHAVE_MEMCPY
* ./memcp