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
window.addEventListener("contextmenu", function(e) { e.preventDefault(); }) |
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 asyncio | |
from random import randint | |
async def download(code): | |
wait_time = randint(1, 3) | |
print('downloading {} will take {} second(s)'.format(code, wait_time)) | |
await asyncio.sleep(wait_time) # I/O, context will switch to main function | |
print('downloaded {}'.format(code)) |
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 asyncio | |
try: | |
loop = asyncio.get_event_loop() | |
except RuntimeError as ex: | |
if "There is no current event loop in thread" in str(ex): | |
loop = asyncio.new_event_loop() | |
asyncio.set_event_loop(loop) | |
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 random | |
import asyncio | |
from aiohttp import ClientSession | |
async def fetch(url, session): | |
async with session.get(url) as response: | |
delay = response.headers.get("DELAY") | |
date = response.headers.get("DATE") | |
print("{}:{} with delay {}".format(date, response.url, delay)) | |
return await response.read() |
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
// adapter design pattern application in go language | |
package main | |
import ( | |
"fmt" | |
"strconv" | |
) | |
// LightBulb class to be adapted to the Lighting interface (Adaptee) | |
// IsOn is a boolean property |
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
// implementing a hash table in go | |
package main | |
import "fmt" | |
// A programmer from China, who loves Go, Python, AI, Machine Learning, and Data Science. To support me join Medium: https://jerryan.medium.com/membership | |
const SIZE = 15 | |
// single linked list |
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" | |
"sync" | |
) | |
func main() { | |
letter, number := make(chan bool), make(chan bool) |
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
// watches the source directory for changes and synchronize to destination directory | |
package main | |
import ( | |
"flag" | |
"fmt" | |
"log" | |
"os" | |
"path/filepath" | |
"strings" |
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" |
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: |