Skip to content

Instantly share code, notes, and snippets.

Run delve in headless mode, logging rpc calls to the delve.out file

= ./go/bin/dlv core adjust_server core.250387 --headless --listen 178.162.216.107:40233 --api-version=2 --log --log-output rpc 2> delve.out

Get list of running goroutines:

= dlv connect 178.162.216.107:40233
goroutines
@narqo
narqo / callback_test.go
Last active August 28, 2018 20:06
Rename struct's fields while keep supporting old JSON data
package callback_test
import (
"encoding/json"
"fmt"
"reflect"
"testing"
"time"
)
function! Group(char)
" open blank line on top of file and jump back
execute "normal! ggO\<Esc>\<C-O>"
" save current position
let p = getpos('.')
" from this line downward move all lines matching the pattern to top of file
.,$g//m0
" select all lines matching the pattern
normal! vip
" redirect output to standard register
#!/usr/bin/env sh
# Usage:
# > to_deploy.sh <branch> <base_branch>
branch=${1:-HEAD}
base=${2:-"origin/master"}
declare -r mains=$(go list -json ./... | jq --compact-output '. | select(.Name == "main") | {ImportPath: .ImportPath, Deps: .Deps}')
declare -r changed=($(git diff --name-only ${base}...${branch} \
@romgrk
romgrk / surround-function.vim
Last active September 18, 2021 18:53
Adds ability to manipulate function calls with vim-surround
" This lets vim-surround be able to surround a motion with a function-call,
" but it's not smart enough to handle delete-surrounding & change-surrounding,
" so it's handled by the functions below
let surround_{char2nr("f")} = "\1func: \1(\r)"
" Mappings
nmap dsf :call DSurroundFunc()<CR>
@Rseding91
Rseding91 / TrainPathFinder.cpp
Last active May 1, 2023 16:28
Factorio TrainPathFinder
#include <Entity/Rail.hpp>
#include <Entity/RailSignalBase.hpp>
#include <Rail/RailBlock.hpp>
#include <Rail/RailPath.hpp>
#include <Rail/TrainPathFinder.hpp>
#include <Rail/RailSegment.hpp>
#include <Rail/RailUtil.hpp>
#include <Rail/Train.hpp>
#include <Util/Container/MinHeap.hpp>
#include <Log.hpp>

Scaling your API with rate limiters

The following are examples of the four types rate limiters discussed in the accompanying blog post. In the examples below I've used pseudocode-like Ruby, so if you're unfamiliar with Ruby you should be able to easily translate this approach to other languages. Complete examples in Ruby are also provided later in this gist.

In most cases you'll want all these examples to be classes, but I've used simple functions here to keep the code samples brief.

Request rate limiter

This uses a basic token bucket algorithm and relies on the fact that Redis scripts execute atomically. No other operations can run between fetching the count and writing the new count.

@andrewslotin
andrewslotin / goba
Last active February 16, 2016 14:58
Find and run all Go tests in current directory (and subdirectories)
#!/bin/bash
declare paths=$(for t in $(find . -name "*_test.go" -not -path "./.go/*"); do dirname $t; done | sort | uniq)
declare -i return_value=0
for path in ${paths[@]}; do
if go test -i $path; then
echo "$path...ok"
else
return_value=1
@jmhodges
jmhodges / doc.go
Last active August 14, 2023 13:24
Generating protobuf Go files with `go generate` and a vendored protobuf package (specifically, vendored with godep).
//go:generate protoc --go_out=import_prefix=github.com/your_github_acct/your_repo/Godeps/_workspace/src/:. your_proto_file.proto
package yourprotopkg
@AndrewRadev
AndrewRadev / dsf.vim
Last active November 5, 2018 05:01
Delete surrounding function call
" Delete surrounding function call
" Relies on surround.vim
"
" function_call(cursor_here) => dsf => cursor_here
"
" Try `dsf` with more complicated structures:
"
" nested(function_call(cursor_here))
" nested(cursor_here(chewy_center))
" One::Two.new([cursor_here])