Skip to content

Instantly share code, notes, and snippets.

View ehernandez-xk's full-sized avatar
Verified

Eddy ehernandez-xk

Verified
  • Guatemala
View GitHub Profile
@ehernandez-xk
ehernandez-xk / serve.sh
Created March 22, 2019 03:26
small python server - share files in the network
#!/bin/bash
python -m SimpleHTTPServer 8000
@ehernandez-xk
ehernandez-xk / for_range.go
Last active September 2, 2018 17:25
for loop with pointer, a gotcha
// Here an example of deep understanding of an unexpected output when use pointers in a loop
// test2 it is clear to understand than test1
// test1 and test2 are equivalent
package main
import (
"fmt"
)
type p struct {
@ehernandez-xk
ehernandez-xk / handler.go
Created May 15, 2017 14:45
http.HandlerFunc wrapper technique
//https://medium.com/@matryer/the-http-handler-wrapper-technique-in-golang-updated-bc7fbcffa702
//wraps the handler do do things before and/or after
func auth(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Println("Before")
h.ServeHTTP(w, r)
fmt.Println("After")
})
}
@ehernandez-xk
ehernandez-xk / vagrant-scp
Created April 12, 2017 13:56 — forked from geedew/vagrant-scp
Copying files to a Vagrant VM from host
#!/bin/sh
# Change these settings to match what you are wanting to do
FILE=/File/To/Copy
SERVER=localhost
PATH=/Where/To/Put/File
OPTIONS=`vagrant ssh-config | awk -v ORS=' ' '{print "-o " $1 "=" $2}'`
scp ${OPTIONS} $FILE vagrant@$SERVER:$PATH
@ehernandez-xk
ehernandez-xk / vagrant-scp
Created April 12, 2017 13:56 — forked from geedew/vagrant-scp
Copying files to a Vagrant VM from host
#!/bin/sh
# Change these settings to match what you are wanting to do
FILE=/File/To/Copy
SERVER=localhost
PATH=/Where/To/Put/File
OPTIONS=`vagrant ssh-config | awk -v ORS=' ' '{print "-o " $1 "=" $2}'`
scp ${OPTIONS} $FILE vagrant@$SERVER:$PATH
@ehernandez-xk
ehernandez-xk / main.go
Last active September 2, 2018 17:25
Add assets to the server (e.g. Bootstrap)
http.Handle("/assets/", http.StripPrefix("/assets", http.FileServer(http.Dir("/path/to/assets/"))))
@ehernandez-xk
ehernandez-xk / upload-file-s3.go
Last active January 31, 2021 00:56
Uploading a file to AWS S3 using aws-sdk-go
/*
https://www.youtube.com/watch?v=iOGIKG3EptI
https://github.com/awslabs/aws-go-wordfreq-sample/blob/master/cmd/uploads3/main.go
https://docs.aws.amazon.com/sdk-for-go/api/aws/
- first configure your aws credentials run: aws configure
- go get -u github.com/aws/aws-sdk-go/aws
- login to UI web aws s3 interface
- go to S3 service
@ehernandez-xk
ehernandez-xk / parse_yaml.sh
Created June 8, 2016 14:40 — forked from pkuczynski/parse_yaml.sh
Read YAML file from Bash script
#!/bin/sh
parse_yaml() {
local prefix=$2
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
awk -F$fs '{
indent = length($1)/2;
vname[indent] = $2;
for (i in vname) {if (i > indent) {delete vname[i]}}
@ehernandez-xk
ehernandez-xk / functionMethods.js
Created November 12, 2015 13:49
javascript - call, bind and apply
var person = {
firstname: "eddy",
lastname: "hernandez",
fullname: function () {
return this.firstname + " " + this.lastname;
}
}
console.log(person.fullname());
@ehernandez-xk
ehernandez-xk / closure2.js
Created November 6, 2015 12:26
javascript - closures
// Closures
// What is the especting output
function builFunctions () {
var arr = [];
for (var i = 0; i < 3; i++) {
arr.push(
function () {
console.log(i);