Skip to content

Instantly share code, notes, and snippets.

--fuinction to get the square of an integer
square::Int->Int
square a = a*a
--function to find the mid of two integers floor to ,lower if fractional
mid::Int->Int->Int
mid a b = (a+b) `div` 2
#!/bin/sh
# Configure your favorite diff program here.
DIFF="/usr/bin/vimdiff"
# Subversion provides the paths we need as the sixth and seventh
# parameters.
LEFT=${6}
RIGHT=${7}
@sarathsp06
sarathsp06 / angular_relativeDate.js
Last active May 9, 2019 09:07
Angular filter to convert a time in milliseconds to relative human readable time
(function(){
"use strict":
angular.module('ng-relativeDate',[])
.filter('ngrelativeDate',function(){
/**
* [humanreadableDate converts the timestamp into human readable time ]
* @param {Int} timestamp - time as number of milliseconds since 1970/01/01:
* @return {string} relative time corresponding to timestamp
*/
@sarathsp06
sarathsp06 / nginx.conf
Created July 1, 2015 06:46
Nginx Config File - OpenVBX
server {
listen 80;
server_name example.sarath.in;
access_log /var/log/nginx/example.sarath/access.log;
error_log /var/log/nginx/example.sarath/error.log;
location ~ ^/assets/ {
autoindex on;
expires 7d;
add_header Last-Modified "";
@sarathsp06
sarathsp06 / goget-bitbucket.sh
Last active August 29, 2015 14:24
Golang - go get initializer tool gor private repositories in bitbucket
#!/usr/bin/env bash
set -o errexit
set -o pipefail
set -o nounset
args=("${@}")
package="${args[0]}"
echo -n "Enter your bitbucket username "
read user_name
@sarathsp06
sarathsp06 / StructToMap.go
Created October 28, 2015 13:16
Function to convert a struct to Map
package main
import (
"fmt"
"reflect"
)
//StructToMap converts a struct to map of string to interface
//Its uses the tag 'map' to check the name to be used
//if the value is nil no key is added
@sarathsp06
sarathsp06 / StrToMap.go
Created October 30, 2015 12:53
A function to converta a striuct to map of string to interface
package main
import (
"fmt"
"reflect"
)
//StructToMap converts a struct to map of string to interface
//Its uses the tag 'map' to check the name to be used
//if the value is nil no key is added
@sarathsp06
sarathsp06 / log_free.sh
Created February 10, 2016 07:14
To watch and log the result of free to a file iusing bash
#!/bin/bash
outfile="$1"
if [ "x$outfile" = "x" ];then
echo 'use log_free oufile';
exit 1;
fi
if [ -t 0 ]; then stty -echo -icanon -icrnl time 0 min 0; fi
keypress=''
while [ "x$keypress" = "x" ]; do
@sarathsp06
sarathsp06 / tmkafka.sh
Last active March 2, 2016 06:29
tmux init script to initialize tmux and kafka opening some windows for playing with nsq in tmux or with kafka in tmux
#!/bin/sh
SESSION_NAME="kafka"
cd /home/kafka/kafka
tmux has-session -t ${SESSION_NAME}
if [ $? != 0 ]
then
# Create the session
# copied from somewhere and tweaked - dont remember the original source
##############################
# _
# | |_ _ __ ___ _ ___ __
# | __| '_ ` _ \| | | \ \/ /
# | |_| | | | | | |_| |> <
# \__|_| |_| |_|\__,_/_/\_\
#
#############################
#