Skip to content

Instantly share code, notes, and snippets.

View smileboywtu's full-sized avatar
🌴
On vacation

wind smileboywtu

🌴
On vacation
View GitHub Profile
@jvmsangkal
jvmsangkal / connection-pool.py
Created October 21, 2015 03:36
Connection Pool PyMySQL
class ConnectionPool():
"""
Usage:
conn_pool = nmi_mysql.ConnectionPool(config)
db = conn_pool.get_connection()
db.query('SELECT 1', [])
conn_pool.return_connection(db)
conn_pool.close()
@smileboywtu
smileboywtu / random.md
Created October 24, 2018 03:33 — forked from joepie91/random.md
Secure random values (in Node.js)

Not all random values are created equal - for security-related code, you need a specific kind of random value.

A summary of this article, if you don't want to read the entire thing:

  • Don't use Math.random(). There are extremely few cases where Math.random() is the right answer. Don't use it, unless you've read this entire article, and determined that it's necessary for your case.
  • Don't use crypto.getRandomBytes directly. While it's a CSPRNG, it's easy to bias the result when 'transforming' it, such that the output becomes more predictable.
  • If you want to generate random tokens or API keys: Use uuid, specifically the uuid.v4() method. Avoid node-uuid - it's not the same package, and doesn't produce reliably secure random values.
  • If you want to generate random numbers in a range: Use random-number-csprng.

You should seriously consider reading the entire article, though - it's

@jewzaam
jewzaam / gist:5a9496f1ca2e5feb07bb
Last active April 1, 2019 08:27
MongoDB replica set in docker
# get it
docker pull mongo
# startup a 3 node replica set
docker run --name mongo-rs-1 -d mongo --nojournal --oplogSize 10 --replSet rs
docker run --name mongo-rs-2 -d mongo --nojournal --oplogSize 10 --replSet rs
docker run --name mongo-rs-3 -d mongo --nojournal --oplogSize 10 --replSet rs
# connect to first node
docker run -it --link mongo-rs-1:mongo1 --link mongo-rs-2:mongo2 --link mongo-rs-3:mongo3 --rm mongo /bin/bash
@josegonzalez
josegonzalez / category.rb
Created August 14, 2010 21:41
Category plugin for Jekyll
module Jekyll
class CategoryIndex < Page
def initialize(site, base, dir, category)
@site = site
@base = base
@dir = dir
@name = 'index.html'
self.process(@name)
self.read_yaml(File.join(base, '_layouts'), 'category_index.html')
@wen-long
wen-long / nali-update.sh
Last active November 18, 2019 03:44
QQWry.Dat is the ip database from http://www.cz88.net/ the website which offers the original code seems won't update any more and the download link refers to another obsolete website original script was from https://www.surfchen.org/nali but it was obsolete because the download link https://chenze.name/wenjian/QQWry.Dat offers an obsolete file a…
#!/bin/sh
qqwry_dat_url="http://update.cz88.net/soft/setup.zip";
qqwry_dat_local_path="/usr/local/share/QQWry.Dat"
curl=`which curl`
wget=`which wget`
workdir="/tmp/QQWry/"
zipname="QQWry.setup.zip"
@dropwhile
dropwhile / install-setup.txt
Last active February 28, 2020 05:43
python serialization speed comparison
virtualenv --no-site-packages hodor
hodor/bin/pip install simplejson ujson cbor tnetstring msgpack-python
curl -s 'http://www.json-generator.com/api/json/get/cvfsLVmKiG?indent=2' > test.json
hodor/bin/python shootout.py
@mivade
mivade / tornadobg.py
Last active March 17, 2020 02:07
Background tasks with tornado and concurrent.futures
"""A simple demonstration of running background tasks with Tornado.
Here I am using a basic TCP server which handles streams and keeps
them open while asynchronously performing a fake task in the
background. In order to test it, simply telnet to localhost port 8080
and start typing things to see that the server receives the messages.
The advantage to running on an executor instead of conventional
threads is that we can more easily shut it down by stopping the
tornado IO loop.
@maedoc
maedoc / show_ascii.py
Created January 17, 2014 09:24
`show()` a matplotlib figure in ASCII
# coding: utf-8
import PIL
import tempfile
def show_ascii(w=200, h=50, chars=' .\',;"oO%8@#'):
from pylab import tight_layout, savefig
tight_layout()
with tempfile.NamedTemporaryFile(suffix='.png') as f:
savefig(f.name)
@marcosvidolin
marcosvidolin / kill_port_process.sh
Last active June 8, 2021 10:34
Linux: How to list and kill a process using a port
# to list all ports that are used
sudo netstat -ntlp | grep LISTEN
# you can obtain a specific port using the following command
sudo netstat -ntlp | grep :8080
# when you execute the command above you will see something like that
tcp 0 0 0.0.0.0:27370 0.0.0.0:* LISTEN 4394/skype
tcp 0 0 127.0.1.1:53 0.0.0.0:* LISTEN 2216/dnsmasq
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 4912/cupsd
@dcalsky
dcalsky / champions.csv
Created December 29, 2019 06:55
LOL champion list
name zh_name title nicknames upper_name
olaf 奥拉夫 狂战士 {} Olaf
galio 加里奥 正义巨像 {} Galio
twistedfate 崔斯特 卡牌大师 {} TwistedFate
leblanc 乐芙兰 诡术妖姬 {} Leblanc
kayle 凯尔 正义天使 {} Kayle
alistar 阿利斯塔 牛头酋长 {} Alistar
nunu 努努和威朗普 雪原双子 {} Nunu
ashe 艾希 寒冰射手 {} Ashe
jax 贾克斯 武器大师 {} Jax