Skip to content

Instantly share code, notes, and snippets.

View burningsky250's full-sized avatar
🎯
Focusing

steven burningsky250

🎯
Focusing
View GitHub Profile
package main
import (
"fmt"
"runtime"
)
// reference: https://stackoverflow.com/questions/28432658/does-go-garbage-collect-parts-of-slices/28432812#28432812
func main() {
manyBigSlices := make([][]int, 10)
use std::thread::{self, sleep};
use std::time::Duration;
#[tokio::test]
async fn test_async_call_sync() {
fn sync_dummy_func() -> i32 {
sleep(Duration::from_secs(1));
1
}
@burningsky250
burningsky250 / channel_memory_order_test.go
Last active July 30, 2024 11:51
golang channel memory order experiment
// reference: https://go.dev/ref/mem#chan
package main
import (
"fmt"
"sync"
"testing"
)
func TestChan(t *testing.T) {
@burningsky250
burningsky250 / rabbitmq_learn.md
Last active October 26, 2019 02:31
rabbitmq notes

rabbitmq exchange type:

  • direct:

    when a queue is bound to this exchange with a specific routing_key(rk), messages coming into the exchange with topic of the same with the routing_key(rk) will be pushed into the queue. if there are multiple queues bound with the same routing key, the message will be fan-outed to all the queues.

  • fan-out

    when a queue is bound to this exchange, whatever the routing key is specified, a message coming into the exchange will be fan-outed to the queue.

  • topic

@burningsky250
burningsky250 / linux_cmdline_tools.md
Created October 20, 2019 02:42
linux command line tools

1. network

  • fping: fast&concurrent ping to multiple hosts
  • jq: json parse in structured way
#!/bin/bash
# bash generate random alphanumeric string
#
# bash generate random 32 character alphanumeric string (upper and lowercase) and
NEW_UUID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
# bash generate random 32 character alphanumeric string (lowercase only)
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1
@burningsky250
burningsky250 / getpath.py
Created April 30, 2019 06:34
python get library path
import sys
import os
print os.path.join(sys.prefix, "lib","python" + sys.version[:3])
@burningsky250
burningsky250 / djang_db_thread_safety_analyse.md
Created January 8, 2019 19:39
django mysql thread-safety analyse

The ConnectionHandler is not a connection -- it only handles connections. It does so in a perfectly thread-safe manner by storing them on self._connections, which is a thread.local instance. The ConnectionHandler overrides getitem to support thread-local connections. When you access connections['default'], it looks if the default attribute exists on self._connections, which is a thread local. If it does, that would be the connection to the default database for the current thread. If it doesn't, it'll create a new one and set it on self._connections. Other threads won't be able to access this connection, since it's set on a thread local object. In the end it pretty much comes down to the public API. Setting a ConnectionHandler on a thread-local object would work as well, but the public API would be more complicated than it currently is, since user code would manually need to check if the

# Autoreloading launcher.
# Borrowed from Peter Hunt and the CherryPy project (https://cherrypy.org/).
# Some taken from Ian Bicking's Paste (http://pythonpaste.org/).
#
# Portions copyright (c) 2004, CherryPy Team (team@cherrypy.org)
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
@burningsky250
burningsky250 / list_dict_construct_performance.md
Last active January 7, 2019 18:46
comparison with many ways to construct a big list(dict):

comparison with many ways to construct a big list:

  1. list repeat
python -m timeit -n 10 -r 10 -v '[0]*10000000'
raw times: 0.561 0.528 0.519 0.516 0.516 0.557 0.516 0.513 0.516 0.509
10 loops, best of 10: 50.9 msec per loop

hint: create python object 'int' once, repeat it 10,000,000 times.