Skip to content

Instantly share code, notes, and snippets.

View guysmoilov's full-sized avatar
🐶

Guy Smoilovsky guysmoilov

🐶
View GitHub Profile
@guysmoilov
guysmoilov / consolidate-prs.yml
Last active May 21, 2023 12:05
Python script to consolidate Github PRs into a single PR, based on labels
# Put this under .github/workflows/consolidate-prs.yml
name: Consolidate PRs
on:
pull_request:
types:
- opened
- synchronize
branches:
- master
@guysmoilov
guysmoilov / named_pipes_test.go
Last active September 1, 2021 18:23
Simple example of using named pipes in go for IPC
import (
"os"
"os/exec"
"path"
"syscall"
"testing"
"time"
)
func TestFifo(t *testing.T) {
@guysmoilov
guysmoilov / Git pre-commit hook for large files.md
Last active February 14, 2024 23:46
Git pre-commit hook for large files

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.

If you find this script useful, you might enjoy our more heavy-duty project FastDS, which aims to make it easier to work with versioning in data science projects.

@guysmoilov
guysmoilov / .gitconfig
Last active September 13, 2022 10:48
My git aliases. Work in progress.
[alias]
br = branch
sh = show
rb = rebase
rbi = rebase -i
st = status
ci = commit
cim = commit -m
cia = commit -a -m
co = checkout
@guysmoilov
guysmoilov / git-objects-by-size.sh
Created November 21, 2019 11:52
List git object sizes
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 February 28, 2019 12:56
Bash script to download large zip files from google drive while confirming the virus scan warning
#!/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
}
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 July 30, 2017 15:42
Saves an octet-stream returned from a REST call as a file
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 12:29
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
guysmoilov / TopicChangingMirrorMakerMessageHandler.scala
Created November 30, 2016 13:18
Topic transforming Kafka mirror maker handler
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