Skip to content

Instantly share code, notes, and snippets.

View ckarthickit2's full-sized avatar

Karthick Chinnathambi ckarthickit2

View GitHub Profile
@ckarthickit2
ckarthickit2 / ssh_multi_keys.md
Last active July 19, 2019 10:31
Multiple SSH Keys on a Single Machine

Having Multiple SSH Keys on a Single Machine

  • ssh_config man page tells us how to configure multiple ssh accouts per PC

  • Create a new SSH Key

      $ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
@ckarthickit2
ckarthickit2 / kotlin_scope_function.md
Created July 21, 2019 04:40
Kotlin Scope Functions with Signature
// Calls the specified function [block] with `this` value as its argument and returns its result.
public inline fun <T, R> T.let(block: (T) -> R): R

//Calls the specified function [block] with `this` value as its receiver and returns its result.
public inline fun <T, R> T.run(block: T.() -> R): R


//Calls the specified function [block] with the given [receiver] as its receiver and returns its result.
public inline fun <T, R> with(receiver: T, block: T.() -> R): R 
@ckarthickit2
ckarthickit2 / hanging_child.js
Last active July 25, 2019 01:31
Demo on Javascript Hanging Promises <https://playcode.io/>
async function fetchA() {
return new Promise(resolve => {
setTimeout(function() {
resolve("slow");
console.log("slow promise is done");
}, 4000);
});
}
async function fetchB() {
@ckarthickit2
ckarthickit2 / multihooks.py
Created July 26, 2019 07:28 — forked from carlos-jenkins/multihooks.py
Delegating script for multiple git hooks
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (C) 2015-2017 Carlos Jenkins <carlos@jenkins.co.cr>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
@ckarthickit2
ckarthickit2 / ktlint_hooks.sh
Last active July 27, 2019 12:14
Klint Git Hooks
#!/bin/sh
#ktlint-git-pre-commit-hook-android.sh
git diff --name-only --cached --relative | grep '\.kt[s"]\?$' | xargs ktlint --android --relative .
if [ $? -ne 0 ]; then exit 1; fi
#ktlint-git-pre-push-hook-android.sh
# https://github.com/shyiko/ktlint pre-push hook
git diff --name-only HEAD origin/$(git rev-parse --abbrev-ref HEAD) | grep '\.kt[s"]\?$' | xargs ktlint --android --relative .
if [ $? -ne 0 ]; then exit 1; fi
@ckarthickit2
ckarthickit2 / GridLayoutManager.java
Created July 30, 2019 10:05 — forked from vganin/GridLayoutManager.java
Workaround for bug with RecycleView focus scrolling when navigating with d-pad (http://stackoverflow.com/questions/31596801/recyclerview-focus-scrolling)
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.View;
/**
* {@link GridLayoutManager} extension which introduces workaround for focus finding bug when
* navigating with dpad.
*
* @see <a href="http://stackoverflow.com/questions/31596801/recyclerview-focus-scrolling">http://stackoverflow.com/questions/31596801/recyclerview-focus-scrolling</a>
@ckarthickit2
ckarthickit2 / python_helpers.py
Created August 2, 2019 00:26
Python Helper snippets
#!/usr/bin/env python3
import fileinput
# Read in the file
with open('file.txt', 'r') as file :
filedata = file.read()
# Replace the target string
filedata = filedata.replace('ram', 'abcd')
@ckarthickit2
ckarthickit2 / python_helpers.py
Created August 2, 2019 00:26
Python Helper snippets
#!/usr/bin/env python3
import fileinput
# Read in the file
with open('file.txt', 'r') as file :
filedata = file.read()
# Replace the target string
filedata = filedata.replace('ram', 'abcd')
@ckarthickit2
ckarthickit2 / CodeVisitor.groovy
Created August 2, 2019 12:21
Code Visitor for parsing Gradle files
SourceUnit unit = SourceUnit.create("gradle", gradleFileToString);
unit.parse();
unit.completePhase();
unit.convert();
visitScriptCode(unit, new parseBuildGradle());
private void visitScriptCode(SourceUnit source, GroovyCodeVisitor transformer) {
source.getAST().getStatementBlock().visit(transformer);
for (Object method : source.getAST().getMethods()) {
MethodNode methodNode = (MethodNode) method;