Skip to content

Instantly share code, notes, and snippets.

View kladov's full-sized avatar

Boris Kladov kladov

View GitHub Profile
@kladov
kladov / since-start.go
Created February 25, 2019 09:31
Time since start
func main() {
start := time.Now()
elapsed := time.Since(start)
log.Printf("Binomial took %s", elapsed)
}
@kladov
kladov / remove-git-submodule.md
Last active December 15, 2018 22:24
Remove git submodule

To remove a submodule you need to:

  • Delete the relevant section from the .gitmodules file.
  • Stage the .gitmodules changes git add .gitmodules
  • Delete the relevant section from .git/config.
  • Run git rm --cached path_to_submodule (no trailing slash).
  • Run rm -rf .git/modules/path_to_submodule (no trailing slash).
  • Commit git commit -m "Removed submodule "
  • Delete the now untracked submodule files rm -rf path_to_submodule
@kladov
kladov / remove-all-branch-keep-master.sh
Last active September 28, 2018 08:27
Remove all local branch but keep master
git branch | grep -v "master" | xargs git branch -D
const (
BYTE = 1.0 << (10 * iota)
KILOBYTE
MEGABYTE
GIGABYTE
TERABYTE
)
lsof -nP -i4TCP:$PORT | grep LISTEN
brew tap grpc/grpc
brew install --with-plugins grpc
// formatRequest generates ascii representation of a request
func formatRequest(r *http.Request) string {
// Create return string
var request []string
// Add the request string
url := fmt.Sprintf("%v %v %v", r.Method, r.URL, r.Proto)
request = append(request, url)
// Add the host
request = append(request, fmt.Sprintf("Host: %v", r.Host))
// Loop through headers
@kladov
kladov / rm-all-docker-images-containers.sh
Created August 10, 2017 13:34
Docker remove all Images and Containers
#!/bin/bash
# Delete all containers
docker rm $(docker ps -a -q)
# Delete all images
docker rmi $(docker images -q)
@kladov
kladov / only-number.js
Last active September 28, 2018 08:26
set only number input
$(function(){
$('#some-element').on('keypress keydown', isNumber);
})
function isNumber(evt) {
evt = (evt) ? evt : window.event;
var charCode = (evt.which) ? evt.which : evt.keyCode;
if (charCode > 31 && (charCode < 48 || charCode > 57) && charCode != 37 && charCode != 39 && charCode != 46) {
return false;
newExcitingAlerts = (function () {
var oldTitle = document.title;
var msg = "New!";
var timeoutId;
var blink = function() { document.title = document.title == msg ? ' ' : msg; };
var clear = function() {
clearInterval(timeoutId);
document.title = oldTitle;
window.onmousemove = null;
timeoutId = null;