Skip to content

Instantly share code, notes, and snippets.

View Abhinav1217's full-sized avatar

Abhinav Kulshreshtha Abhinav1217

View GitHub Profile
# https://superuser.com/questions/1310825/how-to-remove-old-version-of-installed-snaps/1330590#1330590
# https://www.linuxuprising.com/2019/04/how-to-remove-old-snap-versions-to-free.html
#!/bin/bash
# Removes old revisions of snaps
# CLOSE ALL SNAPS BEFORE RUNNING THIS
set -eu
LANG=en_US.UTF-8 snap list --all | awk '/disabled/{print $1, $3}' |
while read snapname revision; do
@Abhinav1217
Abhinav1217 / sumByLong.kt
Created April 20, 2020 17:07
sumByLong() polyfill and similar options.
// Kotlin have sumBy:Int and sumByDouble:Double but many of us work with Long which is missing.
// This is an implementation based on stdlib for sumbydouble
// Save this in your util to make this accessable.
inline fun <T> Iterable<T>.sumByLong(selector: (T) -> Long): Long {
var sum = 0L
for (element in this) {
sum += selector(element)
}
return sum
}
@Abhinav1217
Abhinav1217 / CheckNetwork.java
Last active November 11, 2022 05:02
Network Test on API 29 - Java
package com.example.simplenetwork;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.LinkProperties;
import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.NetworkRequest;
import android.util.Log;
@Abhinav1217
Abhinav1217 / vscode-keybindings.jsonc
Last active October 24, 2019 06:20
VS-Code Keymap
// Place your key bindings in this file to override the defaults
// Make sure you disable/replace old keybindings or else Code can misbehave.
// Use "-" in command if you need to disable any keybinding.
// All keybindings must be either scoped or unique.
[
// Setup advanced-new-file - Need to make my own one day
{
"key": "ctrl+n",
"command": "extension.advancedNewFile"
// Brightness math based on:
// http://www.nbdtech.com/Blog/archive/2008/04/27/Calculating-the-Perceived-Brightness-of-a-Color.aspx
$red-magic-number: 241;
$green-magic-number: 691;
$blue-magic-number: 68;
$brightness-divisor: $red-magic-number + $green-magic-number + $blue-magic-number;
@function sqrt ($r) {
// http://www.antimath.info/css/sass-sqrt-function/
<?php
/**
* A more complete implementation of Java's import statement. For `PHP >=5.0, <=7`
*
* While we do not need it in modern projects, I found this to be really
* helpful for teaching purposes.
*
* This is for teaching purposes only. In real life, composer and namespacing is the way to go.
@Abhinav1217
Abhinav1217 / simple_import.php
Last active December 28, 2018 09:49
A php package simulation with a java style syntax. <Simple way>
<?php
$basePath = "./";
/**
* A simple implementation of Java's import statement.
*
* While we do not need it in modern projects, I found this to be really
* helpful for teaching purposes.

Dynamic SVG image placeholders

How it works

  1. Loads the Potrace Lib (6KB min+gzip)
  2. Starts loading the full res source image
  3. Meanwhile...
  4. Grabs a low res thumbnail from Cloudinary (~5KB)
  5. Uses Potrace to generate an svg from the thumbnail
  6. Colours and fades the SVG in as a crisp, full-size placeholder
@Abhinav1217
Abhinav1217 / certificate.sh
Created December 6, 2018 15:26 — forked from volkancakil/certificate.sh
A basic Self Signed SSL Certificate utility
#!/usr/bin/env bash
# A basic Self Signed SSL Certificate utility
# by Andrea Giammarchi @WebReflection
# https://www.webreflection.co.uk/blog/2015/08/08/bringing-ssl-to-your-private-network
# # to make it executable and use it
# $ chmod +x certificate
# $ ./certificate # to read the how-to
@Abhinav1217
Abhinav1217 / ..git-pr.md
Created August 25, 2018 07:43 — forked from gnarf/..git-pr.md
git pr - Global .gitconfig aliases for Pull Request Managment

Install

Either copy the aliases from the .gitconfig or run the commands in add-pr-alias.sh

Usage

Easily checkout local copies of pull requests from remotes:

  • git pr 4 - creates local branch pr/4 from the github upstream(if it exists) or origin remote and checks it out
  • git pr 4 someremote - creates local branch pr/4 from someremote remote and checks it out