Skip to content

Instantly share code, notes, and snippets.

View chroming's full-sized avatar
💭
I may be slow to respond.

chroming

💭
I may be slow to respond.
View GitHub Profile
@chroming
chroming / pipista.py
Created April 11, 2016 14:45 — forked from pudquick/pipista.py
pipista - pip module (for installing other modules) for Pythonista
import os, os.path, sys, urllib2, requests
class PyPiError(Exception):
def __init__(self, value):
self.value = value
def __str__(self):
return repr(self.value)
def _chunk_report(bytes_so_far, chunk_size, total_size):
if (total_size != None):
@chroming
chroming / Barcode Scanner.py
Created December 25, 2016 09:35 — forked from omz/Barcode Scanner.py
Barcode Scanner.py
# coding: utf-8
# Barcode scanner demo for Pythonista
# Based on http://www.infragistics.com/community/blogs/torrey-betts/archive/2013/10/10/scanning-barcodes-with-ios-7-objective-c.aspx
from objc_util import *
from ctypes import c_void_p
import ui
import sound
found_codes = set()
@chroming
chroming / 0_reuse_code.js
Created January 8, 2017 14:03
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
#coding=utf-8
import sys
from PyQt4 import QtGui
from PyQt4.QtCore import Qt
class MainWindow(QtGui.QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
@chroming
chroming / install PIL
Created January 10, 2017 05:08
安装PIL方式
pip install pillow
@chroming
chroming / python_logging.py
Created January 10, 2017 05:09
python logging记录日志
import logging
logging.basicConfig(filename='%s.log' % today, level=logging.INFO, format='TIME: %(asctime)s -- LEVEL:%(levelname)s -- MESSAGE: %(message)s', datefmt='[%d/%b/%Y %H:%M:%S]')
# 同时在日志文件和控制台记录日志
console = logging.StreamHandler()
console.setLevel(logging.INFO)
formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')
console.setFormatter(formatter)
logging.getLogger('').addHandler(console)
@chroming
chroming / multilist2list.py
Created January 10, 2017 05:13
Python多层List转单层
def switch_re(the_list):
"""
多层list转单层
:param the_list: 需要转换的List
:return: 单层List
"""
if isinstance(the_list, list):
now = the_list[:]
res = []
while now:
@chroming
chroming / current_datetime.py
Created January 10, 2017 05:16
python获取当前日期时间
import datetime
datetime.datetime.now().strftime('%Y_%m_%d_%H_%M_%S')
@chroming
chroming / requests_charset.py
Created January 10, 2017 05:17
requests模块获取charset编码
charset = requests.utils.get_encodings_from_content(response.content)
response.encoding = charset[0]
@chroming
chroming / hexo_cmd
Created January 10, 2017 05:19
hexo 常用命令
hexo new "postName" #新建文章
hexo new page "pageName" #新建页面
hexo generate #生成静态页面至public目录 简写:hexo g
hexo server #开启预览访问端口(默认端口4000,'ctrl + c'关闭server) 简写:hexo s,可用--debug
hexo deploy #将.deploy目录部署到GitHub 简写:hexo d
hexo d -g #组合命令,先生成页面,后部署到Github