Skip to content

Instantly share code, notes, and snippets.

@vthanki
vthanki / dict-trie.cc
Created Sep 15, 2017
Simple Trie implementation of a Word Dictionary
View dict-trie.cc
#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 Sep 15, 2017
Sample heap implementation in C
View heap.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 Aug 2, 2017
Sine wave generator (buggy)
View wave-gen.c
#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 Sep 26, 2016
Handy utility to find out supported sample rates from a sound card. Taken from: http://www.spinics.net/linux/fedora/alsa-user/msg07230.html
View hw_params.c
/*
* 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
Unix Socket example, modified to see the behavior of poll() when remote socket is closed before recv() call is made on server.
View unix_client.c
/*
* 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
RAW Read and Write to NAND partition directly.
View nand_rw.c
/*
* 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 Apr 24, 2016
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
View udp_client_send.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>
View upd_server_recv.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>
@vthanki
vthanki / sendRawEth.c
Last active Apr 22, 2016 — forked from austinmarton/sendRawEth.c
Send a raw Ethernet frame in Linux
View sendRawEth.c
/*
* 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>