public class Program
{
static void Main(string[] args)
{
string message = "Hello World!"; // 07/24/2010 Bob
Console.WriteLine(message); // 07/24/2010 Bob
message = "I am so proud of this code!"; // 07/24/2010 Bob
Console.WriteLine(message); // 07/24/2010 Bob
}
}
public class Program
{
static void Main(string[] args)
{
/* This block of code is no longer needed
* because we found out that Y2K was a hoax
* and our systems did not roll over to 1/1/1900 */
//DateTime today = DateTime.Today;
//if (today == new DateTime(1900, 1, 1))
//{
// today = today.AddYears(100);
// string message = "The date has been fixed for Y2K.";
// Console.WriteLine(message);
//}
}
}
public class Program
{
static void Main(string[] args)
{
/* This is a for loop that prints the
* words "I Rule!" to the console screen
* 1 million times, each on its own line. It
* accomplishes this by starting at 0 and
* incrementing by 1. If the value of the
* counter equals 1 million the for loop
* stops executing.*/
for (int i = 0; i < 1000000; i++)
{
Console.WriteLine("I Rule!");
}
}
}
public class Program
{
static void Main(string[] args)
{
/* I discussed with Jim from Sales over coffee
* at the Starbucks on main street one day and he
* told me that Sales Reps receive commission
* based upon the following structure.
* Friday: 25%
* Wednesday: 15%
* All Other Days: 5%
* Did I mention that I ordered the Caramel Latte with
* a double shot of Espresso?
*/
double price = 5.00;
double commissionRate;
double commission;
if (DateTime.Today.DayOfWeek == DayOfWeek.Friday)
{
commissionRate = .25;
}
else if (DateTime.Today.DayOfWeek == DayOfWeek.Wednesday)
{
commissionRate = .15;
}
else
{
commissionRate = .05;
}
commission = price * commissionRate;
}
}
public class Program
{
static void Main(string[] args)
{
//TODO: I need to fix this someday - 07/24/1995 Bob
/* I know this error message is hard coded and
* I am relying on a Contains function, but
* someday I will make this code print a
* meaningful error message and exit gracefully.
* I just don't have the time right now.
*/
string message = "An error has occurred";
if(message.Contains("error"))
{
throw new Exception(message);
}
}
}
def shell_sort(lists):
# 希尔排序
count = len(lists)
step = 2
group = count / step
while group > 0:
for i in range(0, group):
j = i + group
while j < count:
k = j - group
key = lists[j]
while k >= 0:
if lists[k] > key:
lists[k + group] = lists[k]
lists[k] = key
k -= group
j += group
group /= step
return lists
def bubble_sort(lists):
# 冒泡排序
count = len(lists)
for i in range(0, count):
for j in range(i + 1, count):
if lists[i] > lists[j]:
lists[i], lists[j] = lists[j], lists[i]
return lists
def quick_sort(lists, left, right):
# 快速排序
if left >= right:
return lists
key = lists[left]
low = left
high = right
while left < right:
while left < right and lists[right] >= key:
right -= 1
lists[left] = lists[right]
while left < right and lists[left] <= key:
left += 1
lists[right] = lists[left]
lists[right] = key
quick_sort(lists, low, left - 1)
quick_sort(lists, left + 1, high)
return lists
def select_sort(lists):
# 选择排序
count = len(lists)
for i in range(0, count):
min = i
for j in range(i + 1, count):
if lists[min] > lists[j]:
min = j
lists[min], lists[i] = lists[i], lists[min]
return lists
# 调整堆
def adjust_heap(lists, i, size):
lchild = 2 * i + 1
rchild = 2 * i + 2
max = i
if i < size / 2:
if lchild < size and lists[lchild] > lists[max]:
max = lchild
if rchild < size and lists[rchild] > lists[max]:
max = rchild
if max != i:
lists[max], lists[i] = lists[i], lists[max]
adjust_heap(lists, max, size)
# 创建堆
def build_heap(lists, size):
for i in range(0, (size/2))[::-1]:
adjust_heap(lists, i, size)
# 堆排序
def heap_sort(lists):
size = len(lists)
build_heap(lists, size)
for i in range(0, size)[::-1]:
lists[0], lists[i] = lists[i], lists[0]
adjust_heap(lists, 0, i)
def merge(left, right):
i, j = 0, 0
result = []
while i < len(left) and j < len(right):
if left[i] <= right[j]:
result.append(left[i])
i += 1
else:
result.append(right[j])
j += 1
result += left[i:]
result += right[j:]
return result
def merge_sort(lists):
# 归并排序
if len(lists) <= 1:
return lists
num = len(lists) / 2
left = merge_sort(lists[:num])
right = merge_sort(lists[num:])
return merge(left, right)
import math
def radix_sort(lists, radix=10):
k = int(math.ceil(math.log(max(lists), radix)))
bucket = [[] for i in range(radix)]
for i in range(1, k+1):
for j in lists:
bucket[j/(radix**(i-1)) % (radix**i)].append(j)
del lists[:]
for z in bucket:
lists += z
del z[:]
return lists
我们在项目开发中,接触到的变量、函数、类多数都是项目自己定义的,往往都是为了解决一些特定的领域的问题,引入了各种各样的概念,代码里面的名字就对应着问题领域或方案领域的这些概念,所以,对于一个命名良好,代码规范,设计简洁的系统,要想非常快的理解一个系统,最直接的方式就是RTFC(Read The Fucking Code)。对于一个不断演进的系统,代码的可读性至关重要,首要要解决的问题就是名字,变量名、函数名、类名等都需要仔细斟酌,认真对待,一个能够简洁,能够清晰表达概念和意图的名字就显得尤为重要。
tecmint@tecmint ~/Linux-Tricks $ whatis bash
bash (1) - GNU Bourne-Again SHell
tecmint@tecmint ~/Linux-Tricks $ whatis find
find (1) - search for files in a directory hierarchy
tecmint@tecmint ~/Linux-Tricks $ whatis ls
ls (1) - list directory contents
用 which 命令定位命令
which 命令用于定位文件系统中的命令。
tecmint@tecmint ~/Linux-Tricks $ which mkdir
/bin/mkdir
tecmint@tecmint ~/Linux-Tricks $ which bash
/bin/bash
tecmint@tecmint ~/Linux-Tricks $ which find
/usr/bin/find
tecmint@tecmint ~/Linux-Tricks $ $ which ls
/bin/ls
5.处理 Linux 系统的时间
在联网环境中,保持你 Linux 系统时间准确是一个好的习惯。Linux 系统中有很多服务要求时间正确才能在联网条件下正常工作。
让我们来看看你可以用来管理你机器时间的命令。在 Linux 中,有两种方式管理时间:系统时间和硬件时间。
系统时间由系统时钟管理,硬件时间由硬件时钟管理。
要查看你的系统时间、日期和时区,像下面这样使用 date 命令。
tecmint@tecmint ~/Linux-Tricks $ date
Wed Sep 9 12:25:40 IST 2015
像下面这样用 date -s 或 date -set=“STRING” 设置系统时间。
tecmint@tecmint ~/Linux-Tricks $ sudo date -s "12:27:00"
Wed Sep 9 12:27:00 IST 2015
tecmint@tecmint ~/Linux-Tricks $ sudo date --set="12:27:00"
Wed Sep 9 12:27:00 IST 2015
你也可以像下面这样设置时间和日期。
tecmint@tecmint ~/Linux-Tricks $ sudo date 090912302015
Wed Sep 9 12:30:00 IST 2015
使用 cal 命令从日历中查看当前日期。
tecmint@tecmint ~/Linux-Tricks $ cal
September 2015
Su Mo Tu We Th Fr Sa
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
使用 hwclock 命令查看硬件时钟时间。
tecmint@tecmint ~/Linux-Tricks $ sudo hwclock
Wednesday 09 September 2015 06:02:58 PM IST -0.200081 seconds
// getValues() returns a COPY of the $values array, so this adds a 'test' element
// to a COPY of the $values array, but not to the $values array itself.
$config->getValues()['test']='test';
// getValues() again returns ANOTHER COPY of the $values array, and THIS copy doesn't
// contain a 'test' element (which is why we get the "undefined index" message).
echo $config->getValues()['test'];
A:所给程序存在未定义的行为。程序违反了编译器的强重叠规则(strict aliasing)。虽然 int 在第 (2) 行被改变了,但是编译器可以假设任何的 long 都没有改变。我们不能间接引用那些和其他不兼容类型指针相重名的指针。这就是编译器之所以可以传递和在第一行的执行过程中被读取的相同的 long (第(3)行)的原因。
e5f4b49 Re-adding ConfigurationPostProcessorTests after its brief removal in r814. @Ignore-ing the testCglibClassesAreLoadedJustInTimeForEnhancement() method as it turns out this was one of the culprits in the recent build breakage. The classloader hacking causes subtle downstream effects, breaking unrelated tests. The test method is still useful, but should only be run on a manual basis to ensure CGLIB is not prematurely classloaded, and should not be run as part of the automated build.
2db0f12 fixed two build-breaking issues: + reverted ClassMetadataReadingVisitor to revision 794 + eliminated ConfigurationPostProcessorTests until further investigation determines why it causes downstream tests to fail (such as the seemingly unrelated ClassPathXmlApplicationContextTests)
147709f Tweaks to package-info.java files
22b25e0 Consolidated Util and MutableAnnotationUtils classes into existing AsmUtils
7f96f57 polishing
Summarize changes in around 50 characters or less
More detailed explanatory text, if necessary. Wrap it to about 72
characters or so. In some contexts, the first line is treated as the
subject of the commit and the rest of the text as the body. The
blank line separating the summary from the body is critical (unless
you omit the body entirely); various tools like `log`, `shortlog`
and `rebase` can get confused if you run the two together.
Explain the problem that this commit is solving. Focus on why you
are making this change as opposed to how (the code explains that).
Are there side effects or other unintuitive consequenses of this
change? Here's the place to explain them.
Further paragraphs come after blank lines.
- Bullet points are okay, too
- Typically a hyphen or asterisk is used for the bullet, preceded
by a single space, with blank lines in between, but conventions
vary here
If you use an issue tracker, put references to them at the bottom,
like this:
Resolves: #123
See also: #456, #789
$ git commit -m"Fix typo in introduction to user guide"
但如果一个 commit 需要多解释一点,你就要写一下正文。比如:
Derezz the master control program
MCP turned out to be evil and had become intent on world domination.
This commit throws Tron's disc into MCP (causing its deresolution)
and turns it back into a chess game.
这种情况下使用 -m 开关就不太方便。你真的需要一个合适的编辑器。如果你还没有设定好和 git 命令行一起使用的编辑器,可以参考 Pro Git 的这个章节。
无论如何,在浏览日志时,你会发现把标题和正文分开是值得的。下面是完整的日志:
$ git log
commit 42e769bdf4894310333942ffc5a15151222a87be
Author: Kevin Flynn
Date: Fri Jan 01 00:00:00 1982 -0200
Derezz the master control program
MCP turned out to be evil and had become intent on world domination.
This commit throws Tron's disc into MCP (causing its deresolution)
现在执行 git log –online,就只印出主题这行:
$ git log --oneline
42e769 Derezz the master control program
或者,git shortlog,按用户来归类提交信息,为了简洁一样也只显示标题。
$ git shortlog
Kevin Flynn (1):
Derezz the master control program
Alan Bradley (1):
Introduce security program "Tron"
Ed Dillinger (3):
Rename chess program to "MCP"
Modify chess program
Upgrade chess program
Walter Gibbs (1):
Introduce protoype chess program
commit eb0b56b19017ab5c16c745e6da39c53126924ed6
Author: Pieter Wuille
Date: Fri Aug 1 22:57:55 2014 +0200
Simplify serialize.h's exception handling
Remove the 'state' and 'exceptmask' from serialize.h's stream
implementations, as well as related methods.
As exceptmask always included 'failbit', and setstate was always
called with bits = failbit, all it did was immediately raise an
exception. Get rid of those variables, and replace the setstate
with direct exception throwing (which also removes some dead
code).
As a result, good() is never reached after a failure (there are
only 2 calls, one of which is in tests), and can just be replaced
by !eof().
fail(), clear(n) and exceptions() are just never called. Delete
them.
树莓派是 Raspberry Pi Foundation 推出的迷你电脑,它只有信用卡大小,但可以完成一台普通 PC 能完成的大部分工作,并且价格很便宜,是电脑爱好者的不二选择,如果你是一名 Linuxer 更应该拥有一台这样的迷你电脑。
发展
Raspberry Pi 自 2012 年发布以来,依次发布了 Raspberry Pi 1 A , Raspberry Pi 1 B ,Raspberry Pi 1 B+ ,Raspberry Pi 1 A+ ,Raspberry 2 B 五个版本,这些版本硬件上有不少变化,具体可以查阅 Wikipedia Raspberry Pi ,另外 Raspberry Pi 2 B 将支持 Windows 10 iot ,这对非 Linux 用户来说也是一个福音,因为你可以完全把 Raspberry Pi 2 B 当成你的另一台 Windows PC ,详情可以查看 Raspberry Pi Windows 10 iot。
Raspberry Pi 的用途
Raspberry Pi 到底能拿来做什么呢?它的玩法多的数不清了,因为这取决于我们的创意,作为一块开发板,它给我们提供了很大的自由。
## USTC
Server = http://mirrors.ustc.edu.cn/archlinuxarm/armv7h/$repo
编辑好后按 ctrl +x ,然后按 y 保存,然后升级整个系统:
$ sudo pacman -Syu
桌面化 Raspberry Pi
首先安装 xorg
$ sudo pacman -S xorg
$ sudo pacman -S xorg-xinit
然后安装 lxqt 桌面:
$ sudo pacman -S lxqt
使用 vncviewer 访问 Raspberry Pi
首先配置 vncviewer,本机与 Raspberry Pi 都需要安装 tigervnc
$ sudo pacman -S tigervnc
在 Raspberry Pi 中执行 vncserver
$ vncserver
You will require a password to access your desktops.
Password:
Verify:
Would you like to enter a view-only password (y/n)? n
New 'ArchRaspi:1 (locez)' desktop is ArchRaspi:1
Creating default startup script /home/locez/.vnc/xstartup
Starting applications specified in /home/locez/.vnc/xstartup
Log file is /home/locez/.vnc/ArchRaspi:1.log
$ vncserver -kill :1
Killing Xvnc process ID 400
$ vncserver
New 'ArchRaspi:1 (locez)' desktop is ArchRaspi:1
Starting applications specified in /home/locez/.vnc/xstartup
Log file is /home/locez/.vnc/ArchRaspi:1.log
#!/bin/bash
### Description: Adds users based on provided CSV file
### CSV file must use : as separator
### uid:username:comment:group:addgroups:/home/dir:/usr/shell:passwdage:password
### Written by: Benjamin Cane - ben@example.com on 03-2012
if [ -d $FILE_PATH ]
then
for FILE in $(ls $FILE_PATH/*)
do
echo "This is a file: $FILE"
done
else
echo "exiting... provided file path does not exist or is not a directory"
exit 1
fi
# /sbin/ip -6 addr show dev eth0
2: eth0: mtu 1500 qdisc pfifo_ fast qlen 100
inet6 fe80::210:a4ff:fee3:9566/10 scope link
inet6 3ffe:ffff:0:f101::1/64 scope global
inet6 fec0:0:0:f101::1/64 scope site
自动设定的地址和它的存活时间:
# /sbin/ip -6 addr show dev eth0
3: eth0: mtu 1500 qdisc pfifo_fast qlen 100
inet6 2002:d950:f5f8:f101:2e0:18ff:fe90:9205/64 scope global dynamic
valid_lft 16sec preferred_lft 6sec
inet6 3ffe:400:100:f101:2e0:18ff:fe90:9205/64 scope global dynamic
valid_lft 2591997sec preferred_lft 604797sec inet6 fe80::2e0:18ff:fe90:9205/10 scope link
在 SQL Server 中也是可以用正则表达式的,不过这个代码片段应该是来自某个产品环境中的,所以,还体贴的照顾了那些把邮件地址写错的人:
select email
from table_name where
patindex ('%[ &'',":;!+=/()<>]%', email) > 0 -- Invalid characters
or patindex ('[@.-_]%', email) > 0 -- Valid but cannot be starting character
or patindex ('%[@.-_]', email) > 0 -- Valid but cannot be ending character
or email not like '%@%.%' -- Must contain at least one @ and one .
or email like '%..%' -- Cannot have two periods in a row
or email like '%@%@%' -- Cannot have two @ anywhere
or email like '%.@%' or email like '%@.%' -- Cannot have @ and . next to each other
or email like '%.cm' or email like '%.co' -- Camaroon or Colombia? Typos.
or email like '%.or' or email like '%.ne' -- Missing last letter
Oracle PL/SQL
这个是不是有点偷懒?尤其是在那些“复杂”的正则表达式之后:
SELECT email
FROM table_name
WHERE REGEXP_LIKE (email, '[A-Z0-9._%-]+@[A-Z0-9._%-]+.[A-Z]{2,4}');
MySQL
好吧,看来最后也一样懒:
SELECT * FROM `users` WHERE `email` NOT REGEXP '^[A-Z0-9._%-]+@[A-Z0-9.-]+.[A-Z]{2,4}$';
迁移容器同时涉及到了上面两个操作,备份和恢复。我们可以将任何一个Docker容器从一台机器迁移到另一台机器。在迁移过程中,首先我们将把容器备份为Docker镜像快照。然后,该Docker镜像或者是被推送到了Docker注册中心,或者被作为tar包文件保存到了本地。如果我们将镜像推送到了Docker注册中心,我们简单地从任何我们想要的机器上使用 docker run 命令来恢复并运行该容器。但是,如果我们将镜像打包成tar包备份到了本地,我们只需要拷贝或移动该镜像到我们想要的机器上,加载该镜像并运行需要的容器即可。
反向代理是 NGINX 最常见的使用方法之一。商业支持的 NGINX Plus 显示了大量有关后端(或“上游 upstream”)的服务器指标,这些与反向代理设置相关的。本节重点介绍了几个 NGINX Plus 用户可用的关键上游指标。
NGINX Plus 首先将它的上游指标按组分开,然后是针对单个服务器的。因此,例如,你的反向代理将请求分配到五个上游的 Web 服务器上,你可以一眼看出是否有单个服务器压力过大,也可以看出上游组中服务器的健康状况,以确保良好的响应时间。
活跃指标
每上游服务器的活跃连接的数量可以帮助你确认反向代理是否正确的分配工作到你的整个服务器组上。如果你正在使用 NGINX 作为负载均衡器,任何一台服务器处理的连接数的明显偏差都可能表明服务器正在努力消化请求,或者是你配置使用的负载均衡的方法(例如round-robin 或 IP hashing)不是最适合你流量模式的。
错误指标
错误指标,上面所说的高于5XX(服务器错误)状态码,是监控指标中有价值的一个,尤其是响应码部分。 NGINX Plus 允许你轻松地提取每个上游服务器的 5xx 错误代码的数量,以及响应的总数量,以此来确定某个特定服务器的错误率。
可用性指标
对于 web 服务器的运行状况,还有另一种角度,NGINX 可以通过每个组中当前可用服务器的总量很方便监控你的上游组的健康。在一个大的反向代理上,你可能不会非常关心其中一个服务器的当前状态,就像你只要有可用的服务器组能够处理当前的负载就行了。但监视上游组内的所有工作的服务器总量可为判断 Web 服务器的健康状况提供一个更高层面的视角。
收集上游指标
NGINX Plus 上游指标显示在内部 NGINX Plus 的监控仪表盘上,并且也可通过一个JSON 接口来服务于各种外部监控平台。在我们的相关文章“NGINX指标收集”中有个例子。
:help
Welcome to Gradle 2.2.1
To run a build, run gradle ...
To see a list of available tasks, run gradle tasks
To see a list of command-line options, run gradle --help
BUILD SUCCESSFUL