Skip to content

Instantly share code, notes, and snippets.

View smoya's full-sized avatar
🛩️
Flying @asyncapi airlines

Sergio Moya smoya

🛩️
Flying @asyncapi airlines
View GitHub Profile
@smoya
smoya / README.md
Last active May 19, 2020 18:02
[Go] POC - Expose spf13/cobra commands via HTTP

[Go] Expose spf13/cobra commands via HTTP poc (do not do this at home)

This poc tries to demonstrate how "easy" can be exposing CLI tools via HTTP API. The example isn't perfect. It doesn't provide a REST API but it just allow to quickly prototype tooling that can be accessible both via CLI or HTTP.

This is a do not do this at home, however it can be used as starting point for interesting approaches.

A bit of context

I decided to do this insane proof of concept in order to (in)validate the idea of exposing cobra commands via HTTP as a quick prototyping framework. Once built, you just need to create commands and the api will expose them. Even though it could be fast for prototyping, this is not the ideal solution as it's super tricky.

@smoya
smoya / chunked_test.go
Created January 17, 2020 13:26
[Go] Stream HTTP Response with chunked transfer encoding.
package main
import (
"bufio"
"context"
"fmt"
"io"
"log"
"net/http"
"net/http/httptest"

Keybase proof

I hereby claim:

  • I am smoya on github.
  • I am smoya (https://keybase.io/smoya) on keybase.
  • I have a public key whose fingerprint is 551D 0285 D0FE EF30 4869 23CC BEC8 92D4 C851 AE30

To claim this, I am signing this object:

@smoya
smoya / docker-compose.yml
Last active March 14, 2017 11:20
Concurrent queries to MongoDB using mgo ends in closed sockets.
version: '2'
services:
mongo:
image: mongo:3.4.2
ports:
- "27018:27017"
restart: always
@smoya
smoya / commit-cs-fix.sh
Last active May 17, 2016 13:21
Tiny script to run a php cs-fix over a range of commits
#!/bin/bash
RANGE_COMMITS_FROM_HEAD=$1
SCRIPT=$2
if [ -z "$RANGE_COMMITS_FROM_HEAD" ]
then
RANGE_COMMITS_FROM_HEAD=1
fi
@smoya
smoya / how_to_move_files_from_one_directory_to_another_inside_a_git_repository.md
Created December 2, 2015 15:41
How to move files from one directory to another inside a git repository
git filter-branch --prune-empty --tree-filter '
if [[ ! -e foo/bar ]]; then
    mkdir -p foo/bar
    git ls-tree --name-only $GIT_COMMIT | xargs -I files mv files foo/bar
fi'

Where foo/bar is the new dir where your files will be placed.

@smoya
smoya / how_to_move_files_between_repositories_preserving_history.md
Last active February 22, 2016 09:59
How to move files between repositories preserving history
  • Orig repo:
INITCOMMIT=$(git rev-list --parents HEAD | egrep "^[a-f0-9]{40}$")
  • Dest repo:
git format-patch --git-dir=/repo_orig/.git --stdout $INITCOMMIT..HEAD | git am
@smoya
smoya / README.md
Last active May 8, 2017 16:41
Get php trace -on segmentation fault- using xdebug
  • Enable the tracer on your xdebug.ini file (see the xdebug.ini file).
  • If you are gonna trace an http request, make sure your xdebug.trace_output_dir is writable by the webserver user (www-data).
  • Execute your script or your request. You can use produce_segmentation.php to test.
  • See the trace file(s) on your xdebug.trace_output_dir.
@smoya
smoya / .gitattributes
Last active March 29, 2022 16:23
Prettify json files output on git diff.
*.json diff=json