Skip to content

Instantly share code, notes, and snippets.

View harish2704's full-sized avatar

Harish Karumuthil harish2704

View GitHub Profile
@harish2704
harish2704 / json_format.sh
Created September 25, 2018 06:37
Pretty print / format JSON from STDIN using nodejs. single line solution.
node -e "console.log( JSON.stringify( JSON.parse(require('fs').readFileSync(0) ), null, 1 ))"
# Exapmle usage
# echo unformated.json | node -e "console.log( JSON.stringify( JSON.parse(require('fs').readFileSync(0) ), null, 1 ))"
@harish2704
harish2704 / dbus_handler.py
Last active April 21, 2018 09:17 — forked from darkxanter/dbus_handler.py
Python DBus handle hibernate, sleep and resume
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'xanter'
#from datetime import datetime
import signal
import time
import dbus
import gobject
import urllib2
CREATE USER 'hari'@'%' IDENTIFIED VIA mysql_native_password USING '***';
--- GRANT USAGE ON *.* TO 'hari'@'%' REQUIRE NONE WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0;
GRANT USAGE ON *.* TO 'hari'@'%' ;
CREATE DATABASE IF NOT EXISTS `hari`;
GRANT ALL PRIVILEGES ON `hari`.* TO 'hari'@'%';
@harish2704
harish2704 / run-parallel.sh
Last active July 1, 2018 17:36
parallel downloading with proxies in shell script
#!/usr/bin/env bash
#
# Usage: run-parallel.sh <URL-list> <proxy-list> <parallel-job-count> <cmd>
# Environment variables
# - SKIP_PROXY_VALIDATION - if set, skip proxy list validation step.
# - OUTPUT - default value is 'tmux' which will send each jobs to tmux session. for any string, output of each jobs will be saved inside directory tree with given name
urlListRaw=$1
proxyListRaw=$2
@harish2704
harish2704 / rpm-mk-build-deps.sh
Last active March 17, 2018 16:22
mk-build-deps equivalent for rpm. Generate dummy rpm package satisfying build deps of a spec file
#!/usr/bin/env bash
#
# Usage: rpm-mk-build-deps.sh <path_to_spec_file>
#
mkBuildDeps(){
specFile=$1
pkgName=$(rpmspec -q $specFile --qf '%{name}')
pkgVersion=$(rpmspec -q $specFile --qf '%{version}')
file-roller --extract-here *
for i in $(ls -d */); do
extId=$( cat $i/metadata.json | grep uuid | sed 's/.*"uuid".*"\(.*\)".*/\1/' );
mv $i $extId;
done
@harish2704
harish2704 / Readme.md
Created December 1, 2017 15:54
Routing network traffic of specific process through specific interface in linux

Consider we have two working ether net connections. One will be set as default by system.

What if we want to route all the network traffic for a specific process through a specific network interface ? In Linux, we can do this easily

My current configuration is this.

enp0s26u1u2 Link encap:Ethernet  HWaddr 02:45:4a:37:5a:28  
@harish2704
harish2704 / server.vim
Last active October 30, 2017 07:00
Simple vimrc for server environments without external plugins
" Plane vimrmc file without any extra plugins. Useful for use in server env
" This file is inspired by spf13's vimrc
" https://gist.github.com/harish2704/7cbc767a61110fd8bbbd05d50a71ebe1
" My custom commands {{{
" Grep for a word
command! -nargs=1 Gr :execute 'grep -nr <f-args> ./ <CR>'
" Add file header to current buffer
@harish2704
harish2704 / css-utils.js
Created September 1, 2017 11:43
Convert / extract all applied styles in DOM element convert it into inline css
function getCss( elem ){
var rules = [].slice.call(window.getMatchedCSSRules( elem ));
return rules.map( rule => rule.style.cssText ).join('');
}
function addInlineCss( elem, isRecurssive ){
elem.setAttribute( 'style', getCss( elem ) );
if( isRecurssive && elem.children.length ){
[].slice.call( elem.children ).forEach( v => addInlineCss(v, true ) )
@harish2704
harish2704 / dummy-express-server.js
Created August 7, 2017 11:06
Dummy express server for logging in comming request
var express = require('express');
var app = express();
var port = process.env.PORT || 4005;
app.use( function( req, res ){
[
'method',
'url',
'headers',
'query',
'body'