Skip to content

Instantly share code, notes, and snippets.

@justlaputa
justlaputa / docker-clean.py
Last active December 13, 2017 14:17
cleanup unused diffs in docker aufs folder
#!/bin/env python
import os
import json
import hashlib
from functools import reduce
import argparse
import logging
import shutil
DOCKER_DIR = '/var/lib/docker'
@kare
kare / go-unit-test-setup-and-teardown-math_setup_and_teardown_test.go
Created November 22, 2016 17:53
Go unit test setup and teardown math_test.go
package math
import "testing"
func setupTestCase(t *testing.T) func(t *testing.T) {
t.Log("setup test case")
return func(t *testing.T) {
t.Log("teardown test case")
}
}
@miztiik
miztiik / python-scrapy-install-centos.sh
Last active March 3, 2021 04:16
Installing scrapy in CentOS
# Install deltarpm to reduce the size of download
yum install -y deltarpm \
&& yum install -y python-pip \
&& pip install --upgrade pip
# Scrapy Pre-Requisites
yum install -y gcc libffi-devel python-devel openssl-devel
yum install -y libxslt-devel libxml++-devel libxml2-devel
pip install lxml incremental
@kalharbi
kalharbi / httprouter-middleware-example.go
Last active May 27, 2022 01:42
Example of using a middleware with [httprouter](https://github.com/julienschmidt/httprouter)
package main
import (
"fmt"
"github.com/julienschmidt/httprouter"
"log"
"net/http"
)
// The type of our middleware consists of the original handler we want to wrap and a message
@CMCDragonkai
CMCDragonkai / nix_string_and_path_concatenation.md
Last active May 17, 2024 17:37
Nix: String and Path Concatenation #nix #nixos

Nix String and Path Concatenation

From Bas van Dijk:

To understand these things I would recommend using nix-repl:

$ nix-repl
Welcome to Nix version 1.11.2. Type :? for help.
@turtlemonvh
turtlemonvh / README.md
Last active November 9, 2022 17:51
Golang Equal JSON Strings

JSON string equality

A little utility for testing if 2 json strings are equal, for use in tests.

Example

go run main.go '{"dog": 5, "cat": 3}' '{"cat":3, "dog": 5}'

Caveats

@threeaccents
threeaccents / openbrowser.go
Created February 25, 2016 18:55
open chrome browser with golang function
// openBrowser tries to open the URL in a browser,
// and returns whether it succeed in doing so.
func openBrowser(url string) bool {
var args []string
switch runtime.GOOS {
case "darwin":
args = []string{"open"}
case "windows":
args = []string{"cmd", "/c", "start"}
default:
@vodolaz095
vodolaz095 / NumberOfTheWeekInMonth.go
Created February 19, 2016 15:33
Get the number of the week in Golang
package main
import(
"fmt"
"time"
)
func NumberOfTheWeekInMonth(now time.Time) int {
beginningOfTheMonth := time.Date(now.Year(), now.Month(), 1, 1, 1, 1, 1, time.UTC)
_, thisWeek := now.ISOWeek()
@ruda
ruda / listchars.vim
Last active March 5, 2024 09:00
Vim: listchars samples
set listchars=tab:→\ ,trail:␣,extends:…,eol:⏎
set listchars=tab:→\ ,trail:␣,precedes:«,extends:»,eol:⏎
set listchars=tab:→\ ,trail:·,precedes:«,extends:»,eol:¶
set listchars=tab:‣\ ,trail:·,precedes:«,extends:»,eol:¬
set listchars=tab:␋\ ,trail:␠,precedes:«,extends:»,eol:␤
set listchars=tab:>-,trail:.,precedes:<,extends:>,eol:$
@enaeseth
enaeseth / objectid_to_uuid.py
Created June 12, 2013 19:29
Convert a MongoDB ObjectID to a valid, semantically similar UUID.
"""
Convert a MongoDB ObjectID to a version-1 UUID.
Python 2.7+ required for datetime.timedelta.total_seconds().
ObjectID:
- UNIX timestamp (32 bits)
- Machine identifier (24 bits)
- Process ID (16 bits)
- Counter (24 bits)