Skip to content

Instantly share code, notes, and snippets.


Guy Smoilovsky guysmoilov

View GitHub Profile
guysmoilov / Git pre-commit hook for large
Last active Oct 9, 2020
Git pre-commit hook for large files
View Git pre-commit hook for large

Git pre-commit hook for large files

This hook warns you before you accidentally commit large files to git. It's very hard to reverse such an accidental commit, so it's better to prevent it in advance.

Since you will likely want this script to run in all your git repos, a script is attached to add this hook to all git repos you create / clone in the future.

Of course, you can just download it directly to the hooks in an existing git repo.


guysmoilov / .gitconfig
Last active Aug 27, 2020
My git aliases. Work in progress.
View .gitconfig
br = branch
sh = show
rb = rebase
st = status
ci = commit
cia = commit -am
co = checkout
rs = reset
uncommit = reset --soft HEAD~1
git rev-list --objects --all \
| git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' \
| sed -n 's/^blob //p' \
| sort -nrk2 \
| cut -c 1-12,41-
guysmoilov /
Created Feb 28, 2019
Bash script to download large zip files from google drive while confirming the virus scan warning
# Usage: gdrive_download 123-abc ./
function gdrive_download () {
CONFIRM=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate "$1" -O- | sed -En 's/.*confirm=([0-9A-Za-z_]+).*/\1/p')
wget --load-cookies /tmp/cookies.txt "$CONFIRM&id=$1" -O $2
rm -f /tmp/cookies.txt
import java.util.Comparator;
import java.util.List;
public class Mystery<T extends Comparable<? super T>> implements Comparator<List<T>> {
public int compare(List<T> l1, List<T> l2) {
guysmoilov / save-js-blob.js
Last active Jul 30, 2017
Saves an octet-stream returned from a REST call as a file
View save-js-blob.js
var toSend = {};
var xmlhttp = new XMLHttpRequest();"POST", "", true);
xmlhttp.setRequestHeader("Content-Type", "application/json");
xmlhttp.onload = function() {
guysmoilov /
Last active May 7, 2018
Java lexicographical comparator for lists
import java.util.Comparator;
import java.util.List;
* Compares {@link Comparable} list instances lexicographically.
* Assumes that the lists are not null, that they contain no null elements, and that they are optimized for random access!
* <p>
* Created by Tolstoyevsky on 08/02/2017.
* </p>
guysmoilov / TopicChangingMirrorMakerMessageHandler.scala
Created Nov 30, 2016
Topic transforming Kafka mirror maker handler
View TopicChangingMirrorMakerMessageHandler.scala
import java.util
import java.util.Collections
import kafka.consumer.BaseConsumerRecord
import org.apache.kafka.clients.producer.ProducerRecord
import scala.util.matching.Regex
guysmoilov /
Created Aug 23, 2016
Watch command for long-term monitoring
echo "Watching $1 command"
while sleep 1; do
CURRENT=`eval $1`
if [ "$CURRENT" != "$PREV" ]; then
echo "[`date`]: $CURRENT"
# Usage: arg 1 is number of random lines to generate, arg 2 is length of each line
# Stolen from:
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w $2 | head -n $1
You can’t perform that action at this time.