Skip to content

Instantly share code, notes, and snippets.

go mod edit -module {NEW_MODULE_NAME}
-- rename all imported module
find . -type f -name '*.go' \
-exec sed -i -e 's,{OLD_MODULE},{NEW_MODULE},g' {} \;
@uarun
uarun / 01_IncreaseReplicationFactor.md
Last active February 28, 2023 09:03
Increase replication factor for __consumer_offsets Kafka topic

Increasing replication factor for a topic

  1. Create a custom reassignment plan (see attached file inc-replication-factor.json). In this case we are going from replication factor of 1 to 3.

  2. Run Kafka partition reassignment script:

    kafka-reassign-partitions --zookeeper $ZOOKEEPER_CONNECT \
        --reassignment-json-file /home/liquidnt/inc-replication-factor.json  \
        --execute
    
  3. Verify if the assignment was successful

@SKempin
SKempin / Git Subtree basics.md
Last active May 16, 2024 20:38
Git Subtree basics

Git Subtree Basics

If you hate git submodule, then you may want to give git subtree a try.

Background

When you want to use a subtree, you add the subtree to an existing repository where the subtree is a reference to another repository url and branch/tag. This add command adds all the code and files into the main repository locally; it's not just a reference to a remote repo.

When you stage and commit files for the main repo, it will add all of the remote files in the same operation. The subtree checkout will pull all the files in one pass, so there is no need to try and connect to another repo to get the portion of subtree files, because they were already included in the main repo.

Adding a subtree

Let's say you already have a git repository with at least one commit. You can add another repository into this respository like this:

@un1t
un1t / elastic-bulk.go
Last active October 18, 2021 01:49
golang elasticsearch bulk insert
package main
import (
"fmt"
"gopkg.in/olivere/elastic.v2"
"strconv"
)
type Tweet struct {
User string `json:"user"`
@nimasdj
nimasdj / MimeTypes.php
Last active April 2, 2023 22:21
List of MimeTypes mapped to file extensions
<?php
// I made this array by joining all the following lists + .php extension which is missing in all of them.
// please contribute to this list to make it as accurate and complete as possible.
// https://gist.github.com/plasticbrain/3887245
// http://pastie.org/5668002
// http://pastebin.com/iuTy6K6d
// total: 1223 extensions as of 16 November 2015
$mime_types = array(
'3dm' => array('x-world/x-3dmf'),
'3dmf' => array('x-world/x-3dmf'),
@jcarmena
jcarmena / restoring-sequencing.go
Last active June 9, 2016 22:27
Go: Restoring Sequencing
package main
import (
"fmt"
"math/rand"
"time"
)
func boring(msg string) <-chan Message {
c := make(chan Message)
@ngauthier
ngauthier / timeout_and_tick.go
Created February 10, 2015 18:14
Golang timeout and tick loop
// keepDoingSomething will keep trying to doSomething() until either
// we get a result from doSomething() or the timeout expires
func keepDoingSomething() (bool, error) {
timeout := time.After(5 * time.Second)
tick := time.Tick(500 * time.Millisecond)
// Keep trying until we're timed out or got a result or got an error
for {
select {
// Got a timeout! fail with a timeout error
case <-timeout:
@staltz
staltz / introrx.md
Last active May 18, 2024 05:17
The introduction to Reactive Programming you've been missing
@ungoldman
ungoldman / curl_post_json.md
Last active May 17, 2024 14:50
post a JSON file with curl

How do you POST a JSON file with curl??

You can post a json file with curl like so:

curl -X POST -H "Content-Type: application/json" -d @FILENAME DESTINATION

so for example:

@marcinwyszynski
marcinwyszynski / selfref.go
Created March 6, 2014 00:12
Golang: self-referential functions
// Original idea:
// http://commandcenter.blogspot.nl/2014/01/self-referential-functions-and-design.html
package main
import "fmt"
type Cat struct {
Name string
}