Skip to content

Instantly share code, notes, and snippets.

View zeyneloz's full-sized avatar

zeynel ozdemir zeyneloz

View GitHub Profile
import random
spaceships = {...}
key_list = list(spaceships.keys())
def get_random_ship():
id = random.choice(key_list)
return spaceships[id]
import random
spaceships = {...}
def get_random_ship():
key_list = list(spaceships.keys())
# Pick a random key from key list
id = random.choice(key_list)
return spaceships[id]
import random
spaceships = {...}
def get_random_ship():
# Generate a random spaceship id
id = random.randint(0, 100000000)
return spaceships[id] # KeyError ?
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
)
// HTTPError implements ClientError interface.
type HTTPError struct {
Cause error `json:"-"`
Detail string `json:"detail"`
Status int `json:"-"`
}
func (e *HTTPError) Error() string {
if e.Cause == nil {
return e.Detail
// ClientError is an error whose details to be shared with client.
type ClientError interface {
Error() string
// ResponseBody returns response body.
ResponseBody() ([]byte, error)
// ResponseHeaders returns http status code and headers.
ResponseHeaders() (int, map[string]string)
}
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
)
package main
import (
"encoding/json"
"io/ioutil"
"log"
"net/http"
)
type loginSchema struct {
exports.handler = async (event) => {
// Convert translate lambda output to sendMail lambda input.
event.sendMailInput.message = event.translateOutput.text;
return event;
};
const AWS = require('aws-sdk');
const stepFunctions = new AWS.StepFunctions({});
exports.handler = async (event) => {
const notes = await getNotes(user.id); // Fetch user notes from database.
const sfnInput = { // Prepare Step Functions input
translateInput: { // translate Task will use this input.
text: notes,
language: event.translateTo
},