This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#-*- coding: utf-8 -*- | |
import os.path | |
import logging | |
from mlogging import FileHandler_MP, TimedRotatingFileHandler_MP | |
from functools import partial | |
class LevelFilter(logging.Filter): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 开始的字符串相同 | |
* | |
* @param string $haystack 可能包含子串的字符串 | |
* @param string $needle 要查找的子串 | |
* @return bool | |
*/ | |
function starts_with($haystack, $needle) | |
{ | |
return strncmp($haystack, $needle, strlen($needle)) === 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# 运行环境:Python2.7 (Linux/Windows) | |
""" | |
题目给出的例子有错误,15——按题意规则5优先, | |
应该输出Buzz而不是FizzBuzz | |
好吧,我弄错,规则5只对第一个数字a起作用,那边更简单 | |
""" | |
def count_hundred(a, b, c): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#-*- 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#-*- coding:utf-8 -*- | |
""" | |
VIII 8 | |
XDIX 99 | |
""" | |
numerals = 'IVXLCDM' | |
numdict = dict(zip(numerals, range(len(numerals)))) | |
def is_roman_number(number): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/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; |