Skip to content

Instantly share code, notes, and snippets.

// watches the source directory for changes and synchronize to destination directory
package main
import (
"flag"
"fmt"
"log"
"os"
"path/filepath"
"strings"
@jerryan999
jerryan999 / golang-print-the-sequence-alternately.go
Created December 20, 2021 15:41
Use two goroutines to print the sequence alternately; one goroutine prints numbers, and the other prints letters.
package main
import (
"fmt"
"sync"
)
func main() {
letter, number := make(chan bool), make(chan bool)
@jerryan999
jerryan999 / hash_table_implemnetaion_in_go.go
Last active November 26, 2021 09:40
Hash Tables Implementation in Go
// 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
@jerryan999
jerryan999 / medium-adapt-design-pattern-golang.go
Last active November 20, 2021 16:33
medium-adapt-design-pattern-golang.go
// 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
@jerryan999
jerryan999 / asyncio.py
Created October 9, 2021 12:04 — forked from Rotzke/asyncio.py
Asyncio with semaphores
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()
@jerryan999
jerryan999 / asyncio-queue.py
Last active October 1, 2021 00:31
Implement Producer/Consumer pattern with asyncio.Queue
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)
@jerryan999
jerryan999 / limit_conc_asyncio.py
Created September 29, 2021 10:26
limit concurrency with Python asyncio
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))
@jerryan999
jerryan999 / contextblocker.js
Created April 3, 2021 14:44
contextblocker.js
window.addEventListener("contextmenu", function(e) { e.preventDefault(); })
@jerryan999
jerryan999 / sample.json
Created March 8, 2021 05:49
this is a sample json
{
"center": {
"x": 333.5164489746094,
"y": 104.28516387939453
},
"has_center": true,
"result": [
[
"box",
0.798782229423523,
// Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0' makes TLS connections and HTTPS requests insecure by disabling certificate verification.
const puppeteer = require("puppeteer");
const crypto = require('crypto');
const { proxyRequest } = require('puppeteer-proxy');
// xun proxy
let orderno = 'ZF2020121058569meja6';
let secret = '';