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 | |
import ( | |
"fmt" | |
"log" | |
"net/http" | |
"os" | |
) | |
func handler(w http.ResponseWriter, r *http.Request) { |
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 | |
import "errors" | |
import "fmt" | |
func bar() error { | |
return errors.New("an error") | |
} | |
func main() { |
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
import { ObjectId } from 'mongodb' | |
const Mutation = { | |
createMovie: async (parent, args, { db }) => { | |
const newMovie = { | |
...args.input, | |
created_at: new Date() | |
} | |
const insertedResult = await db.collection('movies').insertOne(newMovie) | |
newMovie.id = insertedResult.insetedId |
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 DoReq() error { | |
resp, err := http.Get("http://localhost:8080/ping") | |
if err != nil { | |
return err | |
} | |
defer resp.Body.Close() | |
if resp.StatusCode < 200 || resp.StatusCode >= 300 { | |
return errors.New("bad response") | |
} |
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
ch := make(chan string, 1) |
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 | |
import "fmt" | |
type User struct { | |
Name string | |
Age int | |
} | |
func (u User) String() string { |
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 MaxInt(args ...int) int { | |
if len(args) == 0 { | |
return *new(int) | |
} | |
max := args[0] | |
for _, arg := range args[1:] { | |
if arg > max { | |
max = arg | |
} | |
} |
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
import discord | |
import asyncio | |
class MyClient(discord.Client): | |
def __init__(self, *args, **kwargs): | |
super().__init__(*args, **kwargs) | |
async def on_ready(self): | |
print(f'Logged in as {self.user} (ID: {self.user.id})') |
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
@app.route("/create", methods=["POST"]) | |
def create_book(): | |
"""" | |
Create a new book | |
""" | |
payload = request.get_json() | |
if "id" in payload: # user cannot pass id when creating a new book | |
payload.pop("id") | |
status = BookModel.Schema().validate(payload, partial=("id",)) # no validation to id | |
if status: |
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 | |
import ( | |
b64 "encoding/base64" | |
"fmt" | |
"github.com/andreburgaud/crypt2go/padding" | |
"golang.org/x/crypto/blowfish" | |
ecb "github.com/haowanxing/go-aes-ecb" |