Skip to content

Instantly share code, notes, and snippets.

View camark's full-sized avatar

Ming Gong camark

View GitHub Profile
@camark
camark / string2int.js
Created April 28, 2016 02:02
字符串转数字
function string2int(s) {
return s.split('').map(function(c){
return c-'0'
}).reduce(function(x,y){
return x*10+y;
})
}
// 测试:
if (string2int('0') === 0 && string2int('12345') === 12345 && string2int('12300') === 12300) {
@camark
camark / normalize.js
Created April 28, 2016 02:03
请把用户输入的不规范的英文名字,变为首字母大写,其他小写的规范名字。输入:['adam', 'LISA', 'barT'],输出:['Adam', 'Lisa', 'Bart']。
'use strict'
function normalize(arr){
function CapStr(s){
var lc_s=s.split('').map(function(x){
return x.toLowerCase()
}).reduce(function(x,y){
return x.concat(y)
})
return lc_s.charAt(0).toUpperCase()+lc_s.slice(1)
@camark
camark / filtersushu.js
Created April 28, 2016 02:13
求一个数组里面的素数
'use strict'
function getPrimes(arr){
return arr.filter(function(x){
if(x<2) {
return false
}
for(var i=2;i<=parseInt(x/2);i++){
if(x%i==0) return false;
}
@camark
camark / nextid.js
Created April 28, 2016 02:21
自增id
'use strict'
function* next_ID(){
var current_id=0
var max=1000
while(current_id<max){
current_id++;
yield current_id;
}
}
作者:张洞之
链接:https://www.zhihu.com/question/28277116/answer/40230530
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
/*
_ooOoo_
o8888888o
88" . "88
(| -_- |)
@camark
camark / build.default.xml
Created May 17, 2016 00:57
ant buildxml of web project
<?xml version="1.0" encoding="UTF-8"?>
<project name="ipnet" default="deleteWar" basedir=".">
<property name="build" value="${basedir}/build" />
<property name="build.class" value="${build}/classes"/>
<property name="src" value="${basedir}/src" />
@camark
camark / python-zabbix.py
Created May 27, 2016 07:38
Get Host use python from zabbix
#!/usr/bin/env python
#coding=utf-8
#导入模块,urllib2是一个模拟浏览器HTTP方法的模块
import json
import urllib2
import sys
from urllib2 import Request, urlopen, URLError, HTTPError
#url and url header
from datetime import datetime
import hashlib
import MySQLdb
conn = MySQLdb.connect (host = "localhost", user = "root", passwd = '',db = "spider",charset = 'utf8')
cursor = conn.cursor ()
#INSERTION/UPDATE Statements
sql="insert ignore into url_queue select * from something"
cursor.execute(sql)
conn.commit()
@camark
camark / pymysqlconn.py
Created June 6, 2016 01:02 — forked from maltzsama/pymysqlconn.py
python working with mysql
#!/usr/bin/python
# versao.py – captura e mostra a versão do MySQL database server.
# importe os modulos do MySQLdb e sys
import MySQLdb
import sys
# Abra uma conexão com o banco de dados
# Tenha certeza de ter trocado o IP, usuario, senha e database para os seus.
connection = MySQLdb.connect (host = “192.168.1.1″, user = “username”, passwd = “password”, db = “database_name”)
@camark
camark / vimrc
Created June 13, 2016 00:19 — forked from keelii/vimrc
vimrc for window
" ------------------------------
" Name: vimrc for windows
" Author: keelii
" Email: [email protected]
" ------------------------------
" Startup {{{
filetype indent plugin on
augroup vimrcEx