Skip to content

Instantly share code, notes, and snippets.

View azhai's full-sized avatar
🪁
Focusing

azhai

🪁
Focusing
View GitHub Profile
@azhai
azhai / install-parallel-centos-6.sh
Created November 19, 2015 07:14 — forked from bzz/install-parallel-centos-6.sh
Install GNU Parallel on CentOS 6
#!/bin/bash
# Install parallel on CentOS 6.
# Assumes you are root. Prefix w/ sudo if not.
cd /etc/yum.repos.d/
#wget http://download.opensuse.org/repositories/home:tange/CentOS_CentOS-5/home:tange.repo
wget http://download.opensuse.org/repositories/home:/tange/CentOS_CentOS-6/home:tange.repo
yum install parallel
@azhai
azhai / logger.py
Last active August 29, 2015 14:20
多进程安全日志
#-*- coding: utf-8 -*-
import os.path
import logging
from mlogging import FileHandler_MP, TimedRotatingFileHandler_MP
from functools import partial
class LevelFilter(logging.Filter):
@azhai
azhai / words.php
Last active June 4, 2016 09:18
words.php
/**
* 开始的字符串相同
*
* @param string $haystack 可能包含子串的字符串
* @param string $needle 要查找的子串
* @return bool
*/
function starts_with($haystack, $needle)
{
return strncmp($haystack, $needle, strlen($needle)) === 0;
<?php
# 运行环境:PHP 5.4+
/* 100以内数字报数,5条规则参照https://www.jinshuju.net/f/EGQL3D */
function count_hundred($a, $b, $c)
{
assert ($a > 0 && $a < 10
&& $b > 0 && $b < 10
&& $c > 0 && $c < 10);
$numbers = range(1, 100);
@azhai
azhai / fizz_buzz.py
Created July 3, 2014 12:34
FizzBuzz
# -*- coding: utf-8 -*-
# 运行环境:Python2.7 (Linux/Windows)
"""
题目给出的例子有错误,15——按题意规则5优先,
应该输出Buzz而不是FizzBuzz
好吧,我弄错,规则5只对第一个数字a起作用,那边更简单
"""
def count_hundred(a, b, c):
@azhai
azhai / fib.py
Created July 3, 2014 12:29
判断一组数中哪些是斐波那契数
#-*- coding:utf-8 -*-
from decimal import Decimal, getcontext
getcontext().prec = 50
PHI = Decimal(0.5) * (Decimal(5).sqrt() + 1)
def rdiff(n):
n = Decimal(n)
a = PHI * n
return Decimal(round(a)) * n - a * n
@azhai
azhai / is_roman_number.py
Created July 3, 2014 12:25
判断是否合法的罗马数字
#-*- coding:utf-8 -*-
"""
VIII 8
XDIX 99
"""
numerals = 'IVXLCDM'
numdict = dict(zip(numerals, range(len(numerals))))
def is_roman_number(number):
@azhai
azhai / count_sublists.py
Last active August 29, 2015 14:03
给一组未排序的自然数,求其所有升序子序列的数量
# -*- coding: utf-8 -*-
"""
给一组未排序的自然数,求其所有升序子序列的数量
Ex1:
给定5个数 3 1 2 5 4
结果为 8
[3],[1],[1,2],[1,2,5],[2],[2,5],[5],[4]
Ex2:
给定20个数 1 5 4 3 7 8 9 10 2 19 17 11 12 13 14 15 20 16 6 18
结果为 48
@azhai
azhai / calc24.php
Created May 9, 2014 06:43
四则运算计算24点
#!/usr/bin/env php
<?php
# 运行环境:PHP 5.3+
/* 四个数字, 用四则运算和括号得到24 */
function calc24($a, $b, $c, $d)
{
$nums = func_get_args();
assert (is_int($a) && is_int($b)
&& is_int($c) && is_int($d));
@azhai
azhai / change_root_password.sh
Last active August 29, 2015 13:56
mysql 修改root密码
/etc/init.d/mysql stop
/etc/init.d/mysql start --skip-grant-tables
#回车输入空密码
mysql -u root -p
--执行SQL语句
UPDATE mysql.user SET Password=PASSWORD('my-new-password') WHERE User='root';
FLUSH PRIVILEGES;
quit;