Skip to content

Instantly share code, notes, and snippets.

View harish2704's full-sized avatar

Harish Karumuthil harish2704

View GitHub Profile
@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 / 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
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 / 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}')
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 / 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
@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 / 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 / snmp_count_process.sh
Created December 28, 2018 20:36
Count number of process matching given process name and arguments using snmp protocol
#!/bin/bash
listProcessNameMib=.1.3.6.1.2.1.25.4.2.1.2
listProcessArgsMib=.1.3.6.1.2.1.25.4.2.1.5
snmpHost=$1
snmpCommunity=$2
shift
shift
processName=$@
@harish2704
harish2704 / grub.cfg
Last active June 6, 2019 13:41
grub.cfg for live boot of custom usb drive
set menu_color_normal=white/black
set menu_color_highlight=black/light-gray
menuentry "Try openSUSE Tumbleweed GNOME Live ISO" {
set gfxpayload=keep
set iso_path=/openSUSE-Tumbleweed-GNOME-Live-x86_64-Snapshot20180220-Media.iso
loopback loop0 ${iso_path}
echo Loading kernel...