Skip to content

Instantly share code, notes, and snippets.

View bbrodriges's full-sized avatar

bbrodriges bbrodriges

View GitHub Profile
package store
import (
"context"
"errors"
"fmt"
"net/url"
"github.com/gofrs/uuid"
)
@bbrodriges
bbrodriges / launch.json
Last active July 24, 2018 17:30
[golang] vscode debug
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Delve",
"type": "go",
"request": "launch",
@bbrodriges
bbrodriges / gocyclo_status.sh
Last active October 4, 2016 11:22
Golang cyclomatic complexity one line script
gocyclo . | awk '{if ($1 > 20) {if (status == 0) {printf "\033[1;31mCyclomatic complexity too high:\033[0m\n"}; compl = $1; $1 = ""; print "\033[31;4m" compl "\033[0m", $0; status = 1}} END {exit status}'
@bbrodriges
bbrodriges / go-vendoring.sh
Created March 13, 2016 08:46
Golang vendoring oneliner
# Example: $ ./go-vendoring.sh github.com/gin-gonic/gin
#
# Step-by-step explanation
# 1. Create vender folder in current directory
# 2. Downloads package with dependencies
# 3. Creates subfolders in vendor folder for any donloaded packages
# 4. Copies downloaded packages from $GOPATH/src/ into created subdirectories
mkdir -p vendor && go get -v -u -d $1 2>&1 | grep 'download' | awk '{print $1}' | while read package ; do mkdir -p vendor/$package && cp -R $GOPATH/src/$package/* vendor/$package ; done
@bbrodriges
bbrodriges / api.go
Created March 2, 2016 15:40 — forked from peterhellberg/api.go
A tiny example API written in Go using Martini and Redigo
package main
import (
"flag"
"fmt"
"net/http"
"github.com/codegangsta/martini"
"github.com/garyburd/redigo/redis"
"github.com/martini-contrib/render"
@bbrodriges
bbrodriges / rust-python-cffi.md
Created February 4, 2016 20:29 — forked from seanjensengrey/rust-python-cffi.md
Calling Rust from Python/PyPy using CFFI (C Foreign Function Interface)

This is a small demo of how to create a library in Rust and call it from Python (both CPython and PyPy) using the CFFI

Based on http://harkablog.com/calling-rust-from-c-and-python.html which used ctypes

CFFI is nice because:

  • Reads C declarations (parses headers)
  • Works in both CPython and PyPy (included with PyPy)
  • Lower call overhead than ctypes
@bbrodriges
bbrodriges / Vagrantfile
Created April 17, 2015 21:08
Vagrantfile to install 3 Ubuntu Trusty VMs with public DHCP network and rust from host archive
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
['bmo', 'finn', 'jake'].each do |name|
config.vm.define "#{name}" do |node|
node.vm.box = "ubuntu/trusty64"
@bbrodriges
bbrodriges / params_insert.js
Created April 8, 2015 07:30
Ввернуть параметры в GET
$(function() {
function insertParams(params) {
var url_params = window.location.search.substring(1).split('&');
var url_params_obj = {};
// пересобираем GET параметры в объект
for (var p = 0; p < url_params.length; p++) {
var url_param = url_params[p].split('=');
url_params_obj[url_param[0]] = url_param[1];
@bbrodriges
bbrodriges / Vagrantfile
Created August 29, 2014 07:48
My default Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
VM_NAME = "Rainicorn"
IP_ADDRESS = "192.168.100.3"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# Every Vagrant virtual environment requires a box to build off of.