Skip to content

Instantly share code, notes, and snippets.

@vthanki
vthanki / dict-trie.cc
Created September 15, 2017 19:27
Simple Trie implementation of a Word Dictionary
#include <iostream>
#include <map>
#include <string>
using namespace std;
typedef struct dict {
map<char, struct dict *> child_map;
bool is_word;
} dict_t;
@vthanki
vthanki / heap.c
Created September 15, 2017 06:10
Sample heap implementation in C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MIN_HEAP 0
#define MAX_HEAP 1
typedef struct heap {
int *arr;
int size;
@vthanki
vthanki / wave-gen.c
Created August 2, 2017 05:32
Sine wave generator (buggy)
#include <stdio.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <arpa/inet.h>
#include <math.h>
#include <malloc.h>
@vthanki
vthanki / hw_params.c
Last active September 26, 2016 13:22
Handy utility to find out supported sample rates from a sound card. Taken from: http://www.spinics.net/linux/fedora/alsa-user/msg07230.html
/*
* hw_params.c - print hardware capabilities
*
* compile with: gcc -o hw_params hw_params.c -lasound
*/
#include <stdio.h>
#include <alsa/asoundlib.h>
#define ARRAY_SIZE(a) (sizeof(a) / sizeof *(a))
@vthanki
vthanki / unix_client.c
Created May 12, 2016 20:05
Unix Socket example, modified to see the behavior of poll() when remote socket is closed before recv() call is made on server.
/*
* Code borrowed from http://beej.us/guide/bgipc/output/html/multipage/unixsock.html
*/
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
@vthanki
vthanki / nand_rw.c
Last active May 6, 2016 15:43
RAW Read and Write to NAND partition directly.
/*
* The original code was taken from following link.
* http://stackoverflow.com/questions/15336285/write-on-a-mtd-block-device
*
* It is modified for the demonstration purpose.
*/
#include <stdio.h>
#include <fcntl.h>
#include <sys/ioctl.h>
@vthanki
vthanki / udp_client_send.c
Last active April 24, 2016 12:54
Simple udp client to send a message in loop. Modified the code from https://www.cs.cmu.edu/afs/cs/academic/class/15213-f99/www/class26/udpserver.c
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/ioctl.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/ioctl.h>
@vthanki
vthanki / sendRawEth.c
Last active April 22, 2016 10:54 — forked from austinmarton/sendRawEth.c
Send a raw Ethernet frame in Linux
/*
* This program 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.
*/
#include <arpa/inet.h>
#include <linux/if_packet.h>
#include <stdio.h>