Skip to content

Instantly share code, notes, and snippets.

Avatar
😜
code with love @ shanghai

Lingfeng_Ai hanxiaomax

😜
code with love @ shanghai
View GitHub Profile
@hanxiaomax
hanxiaomax / gist:942fef714311c112cafe
Created Aug 13, 2014
用字符串模拟一个列表,转换为Unicode然后再还原为一个列表的方法
View gist:942fef714311c112cafe
uni=unicode('apple,orange')
print uni
print type(uni)
_str=uni.encode('utf-8')
print _str
print type(_str)
_list=list(_str.split(','))
print _list
print ','.join(_list)
@hanxiaomax
hanxiaomax / glob learning-1
Created Aug 17, 2014
1.取路径 2.glob取父级目录 3.sys.argv[0]和__file__的区别
View glob learning-1
from sys import argv
import sys
import glob
import os
script=argv
print os.path.abspath(sys.argv[0])#使用__file__时,命令行和直接运行结果不同,不明白
path=os.path.abspath(sys.argv[0])
#这里sys.argv[0]得到的是相对路径,需要取一下绝对路径
print type(path)
print path+r"../*.md"
@hanxiaomax
hanxiaomax / GFM2pyg.py
Last active Aug 29, 2015
静态方法/装饰器
View GFM2pyg.py
#coding=utf-8
#使用静态方法,装饰器
from sys import argv
import sys
import glob
import os
script,language=argv#return as strings
#TODO:行号
path=os.path.abspath(sys.argv[0])
print path
@hanxiaomax
hanxiaomax / match.py
Last active Aug 29, 2015
正则表达式基础学习笔记
View match.py
#coding:utf-8
import re
#---------------------------
pattern=re.compile(r'.ello')#首先编译正则表达式,主要是为了复用
match=pattern.match('hello world!')#使用match来匹配
if match:
print "-------------"
print match.group()
#--------------------------
@hanxiaomax
hanxiaomax / Aisfun.py
Last active Aug 29, 2015
itertools模块/filter/起名软件/编码
View Aisfun.py
#coding:utf-8
__author__='Lingfeng Ai'
__license__='GPL'
import itertools
class GetName(object):
def __init__(self):
self.num=0
def getResult_ordered(self,filename,list1,list2,list3,list4):
@hanxiaomax
hanxiaomax / getSON.js
Created Nov 21, 2014
根据json创建动态表单
View getSON.js
$(function(){
$("input:radio").change(function(){
var selectedvalue = $("input[name='group']:checked").val();
$.getJSON("/static/select.json",function(data){
$("#apply").empty();
$.each(data,function() {
if (this.catagory==selectedvalue)
{
$.each(this.subcatagory, function() {
$("#apply").append("<option>" + this.name + "</option>");
@hanxiaomax
hanxiaomax / ajax_way_json.js
Created Dec 2, 2014
关于getJSON的一点点小坑
View ajax_way_json.js
$(function(){
$("input:radio").change(function(){
var selectedvalue = $("input[name='group']:checked").val();
//使用getJSON会导致每次都从浏览器缓存里面加载json,ajax就可以实现动态的修改json并加载了
$.ajax({
type: "get",
url:'/static/select.json',
cache: false,//必须为false,否则同样会从缓存中加载
dataType : "json",
success: function(data){
@hanxiaomax
hanxiaomax / cppp531.cpp
Created Oct 4, 2015
派生类调用基类构造函数
View cppp531.cpp
#include <iostream>
using namespace std;
class base
{
public:
base(){};
base(int i):base_(i){};
public:
@hanxiaomax
hanxiaomax / pytrans.py
Last active Apr 2, 2018
翻译指定的.po文件到目标语言,使用translator模块
View pytrans.py
#coding:utf-8
#!/usr/bin/env python
# ----------------------------------------------------------------------------
# "THE BEER-WARE LICENSE" (Revision 42):
# <terry.yinzhe@gmail.com> wrote this file. As long as you retain this notice you
# can do whatever you want with this stuff. If we meet some day, and you think
# this stuff is worth it, you can buy me a beer in return to Terry Yin.
#
# Now google has stop providing free translation API. So I have to switch to
# http://mymemory.translated.net/, which has a limit for 1000 words/day free
@hanxiaomax
hanxiaomax / excel2po.py
Last active Jun 19, 2020
excel读写/po文件转excel
View excel2po.py
#coding=utf-8
#从excel中读取中文,然后写入到po文件中,需要手动复制开头的说明文件,否则poedit不能正常读取
import xlrd
workbook = xlrd.open_workbook('Cura_copy.xls')#打开一个excel
sheet = workbook.sheet_by_name(u'sheet1')#获取一个工作表
buf=sheet.col_values(1)
for i in range(0,len(buf)):
buf[i]=unicode(buf[i]).encode('utf-8')
result=open("result.po",'w')
You can’t perform that action at this time.