Skip to content

Instantly share code, notes, and snippets.

View efueyo's full-sized avatar

Enrique Fueyo efueyo

View GitHub Profile
@efueyo
efueyo / Lambda_IAM_Role.json
Last active June 28, 2017 16:30
Lambda IAM Role
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
@efueyo
efueyo / Lambda_Run_Instance.js
Last active June 28, 2017 16:48
Lambda_Run_Instance
const fs = require('fs');
const aws = require('aws-sdk');
const ec2 = new aws.EC2({ region: 'eu-west-1' });
function getUserData() {
return fs.readFileSync(`${__dirname}/user_data.sh`, { encoding: 'utf-8' });
}
function deployInstance(cb) {
const data = {
ImageId: 'YOUR-AMI-id', // EDIT ME
@efueyo
efueyo / use
Created June 28, 2017 16:56
user_data.sh
#!/usr/bin/env bash
ssh -i ssh_key.pem ec2-user@ip-internal.aws-zone.compute.internal "echo $(date) >> /tmp/task.log";
halt;
@efueyo
efueyo / getIssues.js
Last active June 7, 2018 11:50
Download Titles from Github Repo Issues
const Promise = require('bluebird')
const fs = require('fs')
const octokit = require('@octokit/rest')()
octokit.authenticate({
type: 'basic',
username: 'USER',
password: 'PASS',
})
@efueyo
efueyo / tfidf.py
Last active July 27, 2018 17:04
TF-IDF
# Install dependencies first
#  pip install spacy wikipedia
#  python -m spacy download en
# Run
# python tfidf.py
from collections import Counter
import math
import wikipedia
@efueyo
efueyo / Config.go
Last active October 25, 2019 23:25
Golang Configuration
// Bad
const bark = "woof"
type Dog struct{}
// Bark prints the dog's bark
func (d *Dog) Bark() {
fmt.Println(bark)
}
@efueyo
efueyo / GoldenHelpers.go
Created October 25, 2019 23:30
GoldeFiles
// MustWriteGolden updates the golden file for a given test t.
func MustWriteGolden(t *testing.T, content []byte) {
gp := filepath.Join("testdata", t.Name() +".golden")
if err := ioutil.WriteFile(gp, content, 0644); err != nil {
t.FailF("failed to update golden file: %s", err)
}
}
// MustReadGolden reads the golden file for a given test t.
func MustReadGolden(t *testing.T) (content []byte) {
gp := filepath.Join("testdata", t.Name() +".golden")
@efueyo
efueyo / TestFixtures.go
Last active October 25, 2019 23:44
TestFixtures.go
var fixtures *testfixtures.Context
func TestMain(m *testing.M) { // errors skipped for brevity here
db, _ := sql.Open("postgres", "dbname=myapp_test")
fixtures, _ = testfixtures.NewFolder(db, &testfixtures.PostgreSQL{}, "testdata/fixtures")
os.Exit(m.Run())
}
// now remember to call fixtures.Load() at the beginning of every tests and check for errors
// in Ginkgo you can use BeforeEach like:
@efueyo
efueyo / MustJSONMarshall.go
Created October 25, 2019 23:46
HelperFunctions.go
func MustJSONMarshall(t *testing.T, a interface{}) []byte {
res, err := json.Marshal(a)
if err != nil {
t.FatalF("err: %s", err)
}
return res
}
func TestWhatver(t *testing.T) {
elem := MyStruct{Field:"something"}
elemB := MustJSONMarshall(t, elem)
@efueyo
efueyo / TestServer.go
Last active October 29, 2019 22:25
httptest.Server example
package main_test
import (
"fmt"
"net/http"
"net/http/httptest"
"testing"
)
// GetStatus is the function we want to test. It just return the response.Status.