Skip to content

Instantly share code, notes, and snippets.

@sriramster
sriramster / n_hd.txt
Created October 27, 2013 07:29
Notes from hackers delight
Hacks
+--------------------------------+---------------+-------------------+-----------------------+
|Type |Formula |Example |Code Result |
| | | | |
+--------------------------------+---------------+-------------------+-----------------------+
|1.Test of number being power of |x & (x – 1) |(e.g., 01011000 ⇒ |x = 8 result = 0, x = 9|
|2. | |01010000) |result = 8 |
| | | | |
| | | | |
@sriramster
sriramster / filter.awk
Created October 29, 2013 11:39
Awk stuffs, tried to categorize the ~/Downloads folder inside $HOME.
function _categorize(type,dir) {
matches = ($9 ~ type)
if(matches) {
nlines++
if(dir) {
query = sprintf("cp %s %s",$9,dir)
system(query)
}
}
}
@sriramster
sriramster / sr-dev-init.el
Last active December 30, 2015 04:19
Development mode init stuffs
;;; Handling init-developmental mode stuffs
(defvar devel-file-extension-map
'(("c" c-mode)
("html" html-mode)
("py" python-mode)
("pl" perl-mode)
("php" php-mode)
("scm" scheme-mode)
("java" java-mode)
@sriramster
sriramster / mail.awk
Last active January 2, 2016 00:49
Awk mail search pattern
# Pattern from command Line
BEGIN {
pattern=ARGV[13]
_pattern=pattern
}
{
matches = ($0 ~ _pattern)
if(matches) {
print "Matched Line " $0 "@ " FILENAME
@sriramster
sriramster / bckup.sh
Last active January 2, 2016 12:39
backup script
#!/bin/bash
# Move these stuffs to config, no need to check for last backed date. Run the script every week
DIR=('/home/sriramr/Mail/' '/home/sriramr/pub_webs/Wrk/cdapp/cdapp/')
FILES=('/home/sriramr/src/scratch' '/var/lib/iptable/active')
DROPBOX=('/home/sriramr/src/scratch' '/home/sriramr/src/notes/weekall.org' '/var/lib/iptables/active')
# Not used
CMN_BACKUP_FILE="lastbacked"
CMN_BACKUP_DIR="/store/bckup/"
diff --git a/.gitignore b/.gitignore
index 7a5db30..e7c6a00 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,8 @@
.pc
build
+po/*
+share/ca-certs/Makefile
+share/sounds/Makefile
@sriramster
sriramster / pyaudio.py
Created April 27, 2014 07:30
Python Audio Sampling
import math
import pyaudio
import sys
import numpy as np
PyAudio = pyaudio.PyAudio
RATE = 8000
WAVE = 1000
data = '''
#####
@sriramster
sriramster / emplookup.py
Created April 27, 2014 07:31
Employee LDAP lookup
# Comments Ldap directory search using python_ldap
import os
import sys
import ldap
#debuggin options if required
ldapmodule_trace_level = 0
ldapmodule_trace_file = ''
basedn = "OU=Employees,OU=Domain Users,DC=domain,DC=com"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#define usage() {printf("\n Usage %s file_name", argv[0]);}
int main(int argc, char *argv[])
@sriramster
sriramster / extract.c
Last active August 29, 2015 14:02
bit extraction
#include <stdio.h>
#define bit_ext(val, m, n) \
int k = 1 << (m-1); \
k = k | (k -1); \
k = k ^ (1 << (n + 1)); \
int j = 1 << (n + 1); \
j = j ^ (j - 1); \
k = k ^ j; \
val = val & k; \