Skip to content

Instantly share code, notes, and snippets.

@vsajip
vsajip / client.py
Last active April 30, 2024 03:40
Run a logging socket receiver in a production setting with logging from an example webapp
from concurrent.futures import ThreadPoolExecutor, as_completed
import json
import urllib.request
with open('webapp.json', encoding='utf-8') as f:
config = json.loads(f.read())
URLS = [
'http://localhost:%d/?ident=%d' % (config['port'], ident)
for ident in range(1, 1001)
@premek
premek / mv.sh
Last active March 5, 2024 17:43
Rename files in linux / bash using mv command without typing the full name two times
# Put this function to your .bashrc file.
# Usage: mv oldfilename
# If you call mv without the second parameter it will prompt you to edit the filename on command line.
# Original mv is called when it's called with more than one argument.
# It's useful when you want to change just a few letters in a long name.
#
# Also see:
# - imv from renameutils
# - Ctrl-W Ctrl-Y Ctrl-Y (cut last word, paste, paste)
@ozbillwang
ozbillwang / Git_Behind_Proxy.md
Last active April 20, 2024 15:58
Configure Git to use a proxy (https or SSH+GIT)
@fpagyu
fpagyu / select_demo.py
Created October 10, 2018 06:30
python 中select,poll, epoll 使用例子
# coding: utf-8
import select
import socket
import queue
def select_demo():
server = socket.socket()
server.bind(('127.0.0.1', 9000))
server.listen(5)
@coin8086
coin8086 / using-proxy-for-git-or-github.md
Last active April 7, 2024 07:40
Use Proxy for Git/GitHub

Use Proxy for Git/GitHub

Generally, the Git proxy configuration depends on the Git Server Protocol you use. And there're two common protocols: SSH and HTTP/HTTPS. Both require a proxy setup already. In the following, I assume a SOCKS5 proxy set up on localhost:1080. But it can also be a HTTP proxy. I'll talk about how to set up a SOCKS5 proxy later.

SSH Protocol

When you do git clone ssh://[user@]server/project.git or git clone [user@]server:project.git, you're using the SSH protocol. You need to configurate your SSH client to use a proxy. Add the following to your SSH config file, say ~/.ssh/config:

ProxyCommand nc -x localhost:1080 %h %p
@dgrammatiko
dgrammatiko / chrome.css
Last active December 14, 2020 22:30
Default UA stylesheets
// https://chromium.googlesource.com/chromium/blink/+/master/Source/core/css/html.css
/*
* The default style sheet used to render HTML.
*
* Copyright (C) 2000 Lars Knoll (knoll@kde.org)
* Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@aprilmintacpineda
aprilmintacpineda / Using Multiple SSH keys - Beginner Friendly.md
Last active May 15, 2024 06:45
Beginner Friendly: Using Multiple SSH keys

How to follow this guide

The problem

I have one computer and two different github accounts. One is for work, the other is for my personal stuff. I can't use the same ssh key twice, so I have to use different ssh key for each of my accounts. How do I do that? How do I switch between these ssh keys?

@mayufo
mayufo / 验证中国身份证 前6位对应地区码
Created January 16, 2018 10:12
验证中国身份证 前6位对应地区码
var GB2260 = {
"110000": "北京市",
"110100": "北京市市辖区",
"110101": "北京市东城区",
"110102": "北京市西城区",
"110103": "北京市崇文区",
"110104": "北京市宣武区",
"110105": "北京市朝阳区",
"110106": "北京市丰台区",
"110107": "北京市石景山区",
@demisang
demisang / AesCipher.java
Last active December 16, 2022 02:16
AES/CBC/PKCS5Padding encrypt/decrypt PHP and JAVA example classes
import android.support.annotation.Nullable;
import android.util.Base64;
import java.nio.ByteBuffer;
import java.security.SecureRandom;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
@bloatfan
bloatfan / utf8.php
Created May 9, 2017 13:57
gbk utf8 check
<?php
// refer: http://hustnaive.github.io/php/2015/08/21/php-detect-encoding.html
/**
* 检测字符串编码(注意:存在误判的可能性,降低误判的几率的唯一方式是给出尽可能多的样本$line)
* 检测原理:对给定的字符串的每一个字节进行判断,如果误差与gb18030在指定误差内,则判定为gb18030;与utf-8在指定误差范围内,则判定为utf-8;否则判定为utf-16
* @param string $line
* @return string 中文字符集,返回gb18030(兼容gbk,gb2312,ascii);西文字符集,返回utf-8(兼容ascii);其他,返回utf-16(双字节unicode)
* @author fangl