Skip to content

Instantly share code, notes, and snippets.

View axiaoxin's full-sized avatar
🌙
不忙着圆缺 春天不走远

axiaoxin axiaoxin

🌙
不忙着圆缺 春天不走远
View GitHub Profile
from __future__ import print_function
import dis
def f1():
x = 'a' * 20
y = 'a' * 20
return x is y
@danlmyers
danlmyers / humanbytes.py
Created September 9, 2012 14:15
python humanize bytes
#Humanize byte size figures
def humanize_bytes(bytesize, precision=2):
abbrevs = (
(1<<50, 'PB'),
(1<<40, 'TB'),
(1<<30, 'GB'),
(1<<20, 'MB'),
(1<<10, 'kB'),
(1, 'bytes')
)
@xyuanmu
xyuanmu / step1.py
Last active November 27, 2018 15:58
使用python对ip地址排序所用代码:http://yuanmu.mzzhost.com/tutorials/python-ip-sort.html
iplist=['192.168.1.33','10.5.1.3','10.5.2.4','202.98.96.68','133.120.1.1','192.168.1.22']
import socket
print sorted(iplist, key=socket.inet_aton)
@marazmiki
marazmiki / daemon.py
Created September 4, 2012 07:53
Python daemon example
#!/usr/bin/env python
# coding: utf-8
import argparse
import os
import sys
import time
import atexit
import logging
import signal
@lenage
lenage / fnv_example.go
Created March 31, 2017 01:55
golang fnv example
package main
import (
"bufio"
"fmt"
"hash/fnv"
"io"
"os"
)
@mholt
mholt / stringscontext.go
Last active December 15, 2021 08:48
Functions from the 'strings' package as template actions. Feel free to copy+paste into your project as a starting point.
// Functions from Go's strings package usable as template actions
// with text/template.
//
// This approach assumes you have some context type as a receiver,
// but if you just need the functions check out the FuncMap variant
// below.
//
// Commented functions are not deemed useful in template actions.
// Haven't actually used this, but this is one possible way of doing it.
// Another option is to fill a FuncMap with most of the strings package.
@GianlucaGuarini
GianlucaGuarini / svgcheckbx_cleaned.js
Last active July 22, 2022 02:21
Cleaned version of the svgcheckbx.js file used in this demo http://tympanus.net/Development/AnimatedCheckboxes/
;(function(document, window, undefined) {
// wrap always your modules to avoid the namespace pollution
// use always the strict statement
'use strict';
// you do not need to wrap all your code in an if statement...
if (!document.createElement('svg').getAttributeNS) return;
// shortcut to select any DOM element
var $ = document.querySelectorAll.bind(document),
// create an array with all the inputs to uste
// BTW I am sure that this solution is neither correct but it comes from the original code logic
@debbbbie
debbbbie / 16-62进制互转
Last active August 26, 2022 12:39
[python]16-62进制互转
#coding=gbk
#
#62进制,特别合于月、日、时、分、秒的压缩进储
#
digit62 = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
#整数转化为62进制字符串
#入口:
# x : 整数
#返回: 字符串
def int_to_str62( x ):
@justinfx
justinfx / enc_dec_test.py
Last active October 16, 2022 13:28
Speed test of common serializers on python 2.7.2 (pickle, cPickle, ujson, cjson, simplejson, json, yajl, msgpack)
"""
Dependencies:
pip install tabulate simplejson ujson yajl msgpack
"""
from timeit import timeit
from tabulate import tabulate
setup = '''d = {
'words': """