Skip to content

Instantly share code, notes, and snippets.

Avatar
🐼

Guy Smoilovsky guysmoilov

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

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.

Installation

@guysmoilov
guysmoilov / .gitconfig
Last active Aug 27, 2020
My git aliases. Work in progress.
View .gitconfig
[alias]
br = branch
sh = show
rb = rebase
st = status
ci = commit
cia = commit -am
co = checkout
rs = reset
uncommit = reset --soft HEAD~1
View git-objects-by-size.sh
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
guysmoilov / gdrive_download.sh
Created Feb 28, 2019
Bash script to download large zip files from google drive while confirming the virus scan warning
View gdrive_download.sh
#!/bin/sh
# Usage: gdrive_download 123-abc ./output.zip
function gdrive_download () {
CONFIRM=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate "https://drive.google.com/uc?export=download&id=$1" -O- | sed -En 's/.*confirm=([0-9A-Za-z_]+).*/\1/p')
wget --load-cookies /tmp/cookies.txt "https://drive.google.com/uc?export=download&confirm=$CONFIRM&id=$1" -O $2
rm -f /tmp/cookies.txt
}
View Mystery.java
import java.util.Comparator;
import java.util.List;
/**
???
**/
public class Mystery<T extends Comparable<? super T>> implements Comparator<List<T>> {
@Override
public int compare(List<T> l1, List<T> l2) {
@guysmoilov
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();
xmlhttp.open("POST", "https://myserver.com/path", true);
xmlhttp.responseType="blob";
xmlhttp.setRequestHeader("Content-Type", "application/json");
xmlhttp.overrideMimeType('application/octet-stream');
xmlhttp.onload = function() {
console.log('success');
console.log(xmlhttp.response);
window.open(URL.createObjectURL(xmlhttp.response)).focus();
@guysmoilov
guysmoilov / ListComparator.java
Last active May 7, 2018
Java lexicographical comparator for lists
View ListComparator.java
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
guysmoilov / TopicChangingMirrorMakerMessageHandler.scala
Created Nov 30, 2016
Topic transforming Kafka mirror maker handler
View TopicChangingMirrorMakerMessageHandler.scala
package kafka.tools
import java.util
import java.util.Collections
import kafka.consumer.BaseConsumerRecord
import kafka.tools.MirrorMaker.MirrorMakerMessageHandler
import org.apache.kafka.clients.producer.ProducerRecord
import scala.util.matching.Regex
@guysmoilov
guysmoilov / watch-list.sh
Created Aug 23, 2016
Watch command for long-term monitoring
View watch-list.sh
echo "Watching $1 command"
PREV=""
while sleep 1; do
CURRENT=`eval $1`
if [ "$CURRENT" != "$PREV" ]; then
echo "[`date`]: $CURRENT"
PREV=$CURRENT
fi
done
View generate-random-lines.sh
# Usage: arg 1 is number of random lines to generate, arg 2 is length of each line
# Stolen from: https://gist.github.com/earthgecko/3089509
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w $2 | head -n $1
You can’t perform that action at this time.