Skip to content

Instantly share code, notes, and snippets.

View devendranaga's full-sized avatar
🍈

Dev devendranaga

🍈
  • Bangalore
View GitHub Profile
@devendranaga
devendranaga / go_template.py
Created June 12, 2015 10:40
A simple template to generate a basic golang program
#!/usr/bin/python
import os
import sys
if len(sys.argv) == 1:
print "./template <filename> <package name> <imports>"
exit(0)
filename=sys.argv[1]
#!/usr/bin/python
# only has seconds resolution
class Profile:
def profile_start(self):
self.start = time.gmtime()
def profile_stop(self):
self.stop = time.gmtime()
def profile_display(self):
#!/usr/bin/python
import psutil
print "num cpus " + str(psutil.cpu_count(logical=False))
print "num cpu (total) " + str(psutil.cpu_count())
#!/usr/bin/python
class Lists:
def __init__(self):
self.list = []
def list_head(self):
return self.list[0]
def list_tail(self):
return self.list[len(self.list) - 1]
def list_add_tail(self, elem):
@devendranaga
devendranaga / getsocknames.c
Created June 14, 2015 17:59
get a unix socket name by fd
#include <sys/un.h>
#include <sys/socket.h>
int get_sock_name(int fd, char *name, int name_len)
{
int ret
socklen_t len = sizeof(struct sockaddr_un);
struct sockaddr_un s;
ret = getsockname(fd, (struct sockaddr *)&s, &len);
@devendranaga
devendranaga / string_rand.c
Created June 15, 2015 16:14
random string generator in linux
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/time.h>
char alphabets[] =
{'a', 'A',
'b', 'B',
'c', 'C',
@devendranaga
devendranaga / filesys.c
Last active August 29, 2015 14:23
find the file systems that are available in linux (vfs and mountable)
#include <stdio.h>
#include <stdlib.h>
FILE *fp;
char buffer[1000];
struct fstypes {
int vfs;
char *filesystem;
} fs_types[30];
@devendranaga
devendranaga / signalfd_example.c
Created June 20, 2015 06:06
signalfd() syscall example
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/signalfd.h>
int segv_handle()
{
printf("segv\n");
exit(0);
@devendranaga
devendranaga / rand_gen.c
Created June 20, 2015 13:11
random number generator in c without using srand or rand
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int rand_gen_int()
{
int ret;
int fd;
int number = 0;
@devendranaga
devendranaga / socktype.c
Last active August 29, 2015 14:23
get the socket type (TCP / UDP)
#include <stdio.h>
#include <sys/socket.h>
int opt = -1;
socklen_t optlen = sizeof(opt);
int main(int argc, char **argv)
{
int type;