This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Effect": "Allow", | |
"Action": [ | |
"logs:CreateLogGroup", | |
"logs:CreateLogStream", | |
"logs:PutLogEvents" | |
], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
ssh -i ssh_key.pem ec2-user@ip-internal.aws-zone.compute.internal "echo $(date) >> /tmp/task.log"; | |
halt; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Promise = require('bluebird') | |
const fs = require('fs') | |
const octokit = require('@octokit/rest')() | |
octokit.authenticate({ | |
type: 'basic', | |
username: 'USER', | |
password: 'PASS', | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Install dependencies first | |
# pip install spacy wikipedia | |
# python -m spacy download en | |
# Run | |
# python tfidf.py | |
from collections import Counter | |
import math | |
import wikipedia |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Bad | |
const bark = "woof" | |
type Dog struct{} | |
// Bark prints the dog's bark | |
func (d *Dog) Bark() { | |
fmt.Println(bark) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
OlderNewer