Skip to content

Instantly share code, notes, and snippets.

View gnithin's full-sized avatar
🙂
Pink moon gonna get us all

Nithin Gangadharan gnithin

🙂
Pink moon gonna get us all
View GitHub Profile
@gnithin
gnithin / prepare-commit-msg
Created October 19, 2019 19:26
Hook to prefix commits with branch-name (Skips master, develop and test)
#!/bin/bash
# This way you can customize which branches should be skipped when
# prepending commit message.
if [ -z "$BRANCHES_TO_SKIP" ]; then
BRANCHES_TO_SKIP=(master develop test)
fi
BRANCH_NAME=$(git symbolic-ref --short HEAD)
BRANCH_NAME="${BRANCH_NAME##*/}"
@gnithin
gnithin / backup.sh
Created July 30, 2019 16:52
Back-up repo to local, with all the branches and remote intact
#!/usr/bin/env bash
# Download repo with all of it's branches.
# Run it like this -
# ./backup <REPO-NAME>
# Feel free to push this as `git push --mirror http://github.com/<path-to-new-repo>.git` afterward.
# NOTE(IMP!!!): Change the line with <ORG-NAME> in this file to run this properly.
# This was made in-part to backup most repos from an org.
set -eu

Arrays

Perform operations on sub-arrays iteratively (efficiently)

This can be done very easily using brute force, but if the array-size is huge, then performing the operations on a sub-array iteratively can be expensive. For that, need to basically only measure the delta between additions.

The explanation is detailed properly in the answer given below. Answer link - https://www.geeksforgeeks.org/constant-time-range-add-operation-array/

@gnithin
gnithin / device_info_rn_output.md
Created February 8, 2017 09:56
Output of device info in react native

Output of device-info in react-native.

Iphone - Emulator

2017-01-30 16:35:59.736 [info][tid:com.facebook.react.JavaScript] 'Model - ', 'Simulator' 2017-01-30 16:35:59.736 [info][tid:com.facebook.react.JavaScript] 'Device Unique ID', 'F36F9E59-7C1B-4042-AED2-DCBE53912185' 2017-01-30 16:35:59.736 [info][tid:com.facebook.react.JavaScript] 'Device Manufacturer', 'Apple' 2017-01-30 16:35:59.737 [info][tid:com.facebook.react.JavaScript] 'Device Brand', 'Apple' 2017-01-30 16:35:59.737 [info][tid:com.facebook.react.JavaScript] 'Device Model', 'Simulator'

@gnithin
gnithin / pre-push-hook.sh
Last active December 30, 2016 22:05
A pre-push hook that runs a script, performs a commit and pushes again recursively (Refer to the SO answer mentioned)
#!/bin/sh
# This basically is a pre-push git hook.
# It's run after a connection is established with the remote and before anything is pushed.
# This script basically does this -
# - Executes a file
# - Adds the changes made, to git
# - Pushes the commit to remote
# To prevent the last push to recursively call this hook infinitely,
# referred to this awesome answer (point 3) - http://stackoverflow.com/a/21334985/1518924
@gnithin
gnithin / react-native-notes.md
Last active November 30, 2016 21:05
Notes for the React tutorial and a setting up and woring with react native

Some notes on setting up and working with react-native

I am trying react-native for android (I have a ubuntu distro and an android phone).

Setting it up

I've downloaded the things mentioned here. It's a lot of stuff to download to be honest. Just follow them to the letter. Do NOT try to skip things.

Create a project like this -

@gnithin
gnithin / to_remove.php
Last active September 21, 2016 11:34
Dummy
<?php
function get_x509_public_key($x509_raw, $debug=FALSE)
{
// Insert a '\r\n' every 64 bits
$x509_raw_chunked = chunk_split($x509_raw, 64);
$x509_text = '-----BEGIN CERTIFICATE-----' . "\n" . $x509_raw_chunked . '-----END CERTIFICATE-----';
//$x509_ar = openssl_x509_parse($x509_text);
@gnithin
gnithin / customJSONextractor.cs
Last active September 20, 2016 05:35
Custom Json Extractor
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.WebTesting;
using System.Globalization;
using Newtonsoft.Json.Linq;
namespace CustomJSONExtractor
@gnithin
gnithin / helper_plugin.cs
Last active September 20, 2016 12:12
Helper plugin for partitioning user ids in WebTest
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.WebTesting;
using System.Diagnostics;
namespace ClassLibrary2
{
public class NewClass : WebTestPlugin
@gnithin
gnithin / PHP Overview.md
Last active April 20, 2020 23:43
The good and the bad and the ugly of PHP

What I don't like about php -

  • Different extensions for mysql (There has to be only one proper way to do stuff and migrating between them is HARD)
  • Using references introduces a bucket-load of hard to debug bugs - (Eg: Always set the ref as null after using it, especially when used inside a foreach )
  • Library bugs ( Eg: mb_substr has length param as upper bound on number of CHARs to use (Even if encoding is provided). It's actually the number of bytes, the community doesn't accept that as an error, but it was supposedly intended )
  • utf8_encode is badly named. It's supposed to convert from ISO-8859-1 to utf-8. It ain't a magic wand.
  • Inconsistency in function details. For example -
    array_map	 ( callable $callback, array $array1...)
    array_filter ( array $array, callable $callback...)