C# 正则表达式以分隔URL的锚点部分
private string GetAnchorPart()
{
string anchorExp = "[#].......";
Regex rex = new Regex(anchorExp);
Match anchorMatch = rex.Match(Request.RawUrl);
return anchorMatch.ToString();
}
PHP 电子邮件编码器,以减少垃圾邮件
/**
* Description: E-Mail encoder to reduce spam.
*
* @author Micke Johansson
*
* $mail. The e-mail address to encode.
* $isLink. Set to true to create a link.
* $display. What will be displayed in the browser. If omitted it will display the e-mail address.
*
* @param string $mail
* @param bool $isLink
* @param string $display
* @return string Encoded e-mail or e-mail link
*/
function EncodeMail($mail, $isLink = false, $display = '')
{
$domain = substr($mail,strpos($mail, '@')+1);
$name = substr($mail,0, strpos($mail, '@'));
$encodedDomain = '';
$encodedName = '';
$encodedDisplay = '';
for ($i=0; $i < strlen($domain); $i++)
{
$encodedDomain .= '&#'.ord(substr($domain,$i)).';';
}
for ($i=0; $i < strlen($name); $i++)
{
$encodedName .= '&#'.ord(substr($name,$i)).';';
}
for ($i=0; $i < strlen($display); $i++)
{
$encodedDisplay .= '&#'.ord(substr($display,$i)).';';
}
$script = "<script type=\"text/javascript\">";
$script .= "d=\"".$encodedDomain."\";";
$script .= "n=\"".$encodedName."\";";
if ($isLink)
{
if ($display == '')
$script .= "document.write('<a href=\"&#109;&#097;&#105;&#108;&#116;&#111;&#058;'+n+'&#64;'+d+'\">'+n+'&#64;'+d+'</a>');";
else
$script .= "document.write('<a href=\"&#109;&#097;&#105;&#108;&#116;&#111;&#058;'+n+'&#64;'+d+'\">".$encodedDisplay."</a>');";
}
else
{
$script .= "document.write(n+'&#64;'+d);";
}
$script .= "</script>";
return $script;
}
Bash 系统信息的命令
cat /proc/cpuinfo
free
df -h
hdparm -tT harddisk
Ruby ARTestHelper
# A mixin for Test::Unit classes to ease AR testing
#
# Use in your test class by adding
#
# include ARTestHelper
#
# Written by Nicholas Seckar aka Ulysses
module ARTestHelper
module InstanceMethods
# Access the temporary instance to test.
# In my setup method, I store a new, valid instance in an instance variable such as @p.
#
# The ivar is the first character of the class (@p for Page, @u for User), and usually has an
# attr_reader for it.
#
# This method should return that instance so that the validation checker can access it.
def instance
instance_variable_get("@#{self.class.name[0, 1].downcase}")
end
end
module ClassMethods
# Test that the named associations can be loaded
# Catches errors such as missing tables, classes, etc.
# Only use one directive per test-case
#
# Example: check_associations %w(friends downloads links)
def check_associations(*names)
define_method "test_associations" do
assert(instance.save, 'Must be able to save instance!') if instance.new_record?
names.flatten.each do |assoc|
v = instance.send assoc
v.each { } if v.respond_to?(:each) # Load collections by using each
end
end
end
# Check the validations for the named field
#
# Example:
#
# check_validations_for :email do
# invalid nil, "can't be blank"
# invalid 'boo', /not .* valid .* email/
# valid 'fakeuser@host.com'
# end
def check_validations_for(field, &checks)
define_method("test_validations_for_#{field}") do
ValidationChecker.new(field, checks, self, instance).run
end
end
end
class ValidationChecker < Struct.new(:field_name, :proc, :testcase, :instance)
# Assign the given value to the instance
def assign(value)
instance.send "#{field_name}=", value
end
# Ensure that this value is invalid.
# If a message is supplied, it will be matched against the validation error message.
# The message is matched using === so you can use Regexp's.
def invalid(value, message = nil)
assign value
assert ! instance.valid?, "expected #{field_name} = #{value.inspect} to be invalid"
return unless message
found_msg = instance.errors.on(field_name)
assert message === found_msg, "\nexpected error message: #{message.inspect}\nfound: #{found_msg.inspect}"
end
# Ensure that the given value is valid.
def valid(value)
assign value
assert instance.valid?, "expected #{field_name} = #{value.inspect} to be valid"
assert instance.save # Make sure the database agree's with the validations
end
# Run the validation tests
def run
assert(instance.valid?, "Initial object ought to be valid!")
instance_eval(&proc)
end
def assert
end
undef_method :assert # Use the testcase's method
# Forward missing methods to the testcase if possible
def method_missing(sel, *args)
testcase.respond_to?(sel) ? testcase.send(sel, *args) : super(sel, *args)
end
end
def self.append_features(cls)
cls.send :include, InstanceMethods
class << cls
include ClassMethods
end
end
end
Ruby ARTestHelper的例子
#require 'test/unit' unless defined? $ZENTEST and $ZENTEST
require File.dirname(__FILE__) + '/../test_helper'
class AddressObserverTest < Test::Rails::TestCase
def test_class_instance
assert 1
end
end
class AddressTest < Test::Rails::TestCase
include ARTestHelper
check_associations %w(account addressable)
check_validations_for :street_address do
invalid nil
invalid 'st'
invalid 'st'.ljust(200)
valid 'This is some street address'
end
check_validations_for :city do
invalid nil
invalid 'ci'
invalid 'ci'.ljust(200)
valid 'Funchal'
end
check_validations_for :state do
invalid nil
invalid 's'
invalid 's'.ljust(200)
valid 'Madeira'
valid 'CA'
end
check_validations_for :postal_code do
invalid nil
invalid 'p'
invalid 'p'.ljust(200)
valid '9000-055'
end
def setup
super
@address = @rentacar_account.addresses.find(1)
@a = @address
end
def test_account
assert_a_account_instance
end
def test_account_eh
assert_raise( ArgumentError){ @address.account? }
end
def test_account_equals
assert_equal @address.account, @rentacar_account
@address.account = @property_account
assert_equal @address.account, @property_account
end
def test_addressable
assert_a_addressable_instance
end
def test_addressable_equals
assert_equal @address.addressable, @rentacar_account.branches.find(1)
new_addressable = valid_branch( :parent => @rentacar_account )
@address.addressable = new_addressable
assert_equal @address.addressable, new_addressable
end
def test_build_account
assert_a_account_build
end
def test_create_account
assert_a_account_create
end
def test_has_account_eh
assert @address.has_account?
end
def test_set_account_target
assert_a_account_target
end
def test_set_addressable_target
assert_a_addressable_target
end
def test_build_country
assert_instance_of Globalize::Country, @address.build_country
end
def test_country
assert_a_country_instance
end
def test_country_eh
assert_raise( ArgumentError ){@address.country? }
end
def test_country_equals
@address.country = Globalize::Country.find(:first)
assert_equal Globalize::Country.find(:first), @address.country
end
def test_create_country
assert_a_country_create
end
def test_has_country_eh
assert @address.has_country?
end
def test_set_country_target
assert_a_country_target
end
end
Python 简单的shell()函数
def shell(*cmd):
pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = pipe.communicate()
return pipe.returncode, stdout, stderr
Other vim自动完成
<C-x><C-o>
CSS css ET
body {
text-align: center;
color: #777777;
background-color:#ffffff;
}
#container {
display: table;
width: 750px;
margin: 0 auto;
}
h1 {
margin: 8px 0px 0px 0px;
font-family: "Trebuchet MS", Helvetica, sans-serif;
font-size: 15px;
color: #505050;
letter-spacing: 4px;
padding-bottom: 3px;
border-bottom: 1px #777777 solid;
background-color:#ffffff;
}
/******************************
Header + Navigation Menu
******************************/
#header {
width: 246px;
height: 40px;
float:left;
padding: 25px 0px 25px 0px;
font-family: "Trebuchet MS", Arial, Verdana, sans-serif;
font-size: 36px;
color:#aaaaaa;
background-color:#ffffff;
}
#nav {
clear: both;
text-align: left;
width: 750px;
height: 22px;
border-top: 2px #777777 solid;
border-bottom: 2px #777777 solid;
}
#nav ul {
margin: 0;
padding: 0;
list-style: none;
}
#nav ul li {
margin: 0;
float: right;
}
#nav a {
float: left;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 14px;
font-weight: bold;
letter-spacing: -1px;
padding: 2px 10px 0px 10px;
color: #666666;
text-decoration: none;
background-color:#ffffff;
}
#nav a:hover {
color: #cc0000;
background-color:#ffffff;
}
/******************************
News Updates Column
******************************/
#newsupdate {
width: 240px;
float: left;
}
.newstitle {
margin-top: 8px;
width: 233px;
text-align: left;
padding-left: 7px;
font-family: Arial, Helvetica, sans-serif;
font-size: 17px;
font-weight: bold;
color: #cc0000;
float: left;
background-color:#ffffff;
}
.newstitle span {
color: #666666;
background-color:#ffffff;
}
#newsupdate p {
margin: 0;
padding-left: 3px;
font-family: "Trebuchet MS", Helvetica, sans-serif;
font-size: 14px;
text-align: left;
color: #505050;
background-color:#ffffff;
}
.date {
width: 240px;
float: left;
margin-top: 7px;
text-align: right;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
color: #6A6A6A;
background-color:#ffffff;
}
/******************************
Welcome Message IMG+TEXT
******************************/
.rightcontainer {
width: 510px;
float: right;
}
#welcome {
width: 480px;
height: 150px;
padding: 82px 0px 10px 30px;
border-bottom: 1px #ccc solid;
background: url(images/apple.gif) top right no-repeat;
text-align:left;
font-family: "Trebuchet MS", Arial, Verdana, sans-serif;
font-size: 36px;
color:#aaaaaa;
background-color:#ffffff;
}
/******************************
Webpage Contents
******************************/
#content {
margin-top: 10px;
padding-left: 10px;
width: 500px;
float: right;
}
#content h3 {
width: 500px;
text-align: left;
font-family: "Trebuchet MS", Helvetica, sans-serif;
color: #777777;
float:left;
margin: 0;
background-color:#ffffff;
}
#content p {
margin: 0;
padding: 0;
text-align: left;
font-family: "Trebuchet MS", Helvetica, sans-serif;
font-size: 16px;
color: #000;
background-color:#ffffff;
}
/******************************
images in content if you want - align left or right;
ex: <img src="blah.jpg" class="left" />
******************************/
#content .left {
float: left;
color : #777777;
background-color:#ffffff;
}
#content .right {
float: right;
color : #777777;
background-color:#ffffff;
}
/******************************
Footer
******************************/
#footer {
float: left;
margin-top: 10px;
padding-top: 3px;
width: 750px;
border-top: 1px #a4a4a4 solid;
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
color: #333333;
background-color:#ffffff;
}
#footer a {
color: #cc0000;
text-decoration:none;
background-color:#ffffff;
}
#footer a:active, a:visited {
color: #cc0000;
background-color:#ffffff;
}
#footer a:hover {
color: #666666;
background-color:#ffffff;
}
Other PaéssesEspañol(CSV)
151;Afganistán
2;Albania
17;Alemania
3;Andorra
98;Angola
53;Anguilla
54;Antigua y Barbuda
73;Antillas Holandesas
194;Arabia SaudÃ
97;Argelia
81;Argentina
182;Armenia
55;Aruba
197;Australia
4;Austria
183;Azerbayan
56;Bahamas
184;Bahrain
152;Bangladesh
57;Barbados
6;Bélgica
58;Belice
99;Benin
48;Bermudas
5;Bielorrusia
82;Bolivia
7;Bosnia - Herzegovina
100;Botswana
83;Brasil
154;Brunei
8;Bulgaria
101;Burkina Faso
155;Burma (Myanmar)
102;Burundi
153;Bután
104;Cabo Verde
156;Camboya
103;Camerún
49;Canada
106;Chad
84;Chile
157;China
10;Chipre
85;Colombia
107;Comoros
108;Congo
170;Corea del Norte
174;Corea del Sur
217;Costa de Marfil
60;Costa Rica
9;Croacia
61;Cuba
12;Dinamarca
62;Dominica
86;Ecuador
110;Egipto
64;El Salvador
195;Emiratos Arabes Unidos
112;Eritrea
39;Eslovaquia
40;Eslovenia
1;España
52;Estados Unidos
13;Estonia
113;Etiopia
199;Fiji
172;Filipinas
15;Finlandia
16;Francia
114;Gabón
115;Gambia
185;Georgia
116;Ghana
18;Gibraltar
65;Granada
19;Grecia
50;Groenlandia
66;Guadalupe
201;Guam
67;Guatemala
90;Guayana
88;Guayana Francesa
117;Guinea
111;Guinea Ecuatorial
118;Guinea-Bissau
68;HaitÃ
32;Holanda
69;Honduras
158;Hong Kong
20;HungrÃa
59;I. Caimán
219;I. Cocos (Keeling)
198;I. Cook
14;I. Feroe
89;I. Galápagos
87;I. Malvinas
203;I. Marianas del Norte
204;I. Marshall
133;I. Reunión
212;I. Salomón
218;I. VÃrgenes Británicas
80;I. VÃrgenes EEUU
216;I. Wallis y Futuna
159;India
160;Indonesia
186;Irán
187;Iraq
22;Irlanda
21;Islandia
188;Israel
23;Italia
70;Jamaica
161;Japón
189;Jordania
162;Kazajistán
119;Kenia
163;Kirguizistán
202;Kiribati
190;Kuwait
164;Laos
120;Lesotho
24;Letonia
191;LÃbano
121;Liberia
122;LÃbia
25;Liechtenstein
26;Lituania
27;Luxemburgo
165;Macao
28;Macedonia
123;Madagascar
166;Malasia
124;Malawi
167;Maldivas
125;Mali
29;Malta
128;Marruecos
71;Martinica
127;Mauricio
126;Mauritania
51;México
205;Micronesia
30;Moldavia
31;Mónaco
168;Mongolia
72;Montserrat
129;Mozambique
130;Namibia
206;Nauru
169;Nepal
74;Nicaragua
131;NÃger
132;Nigeria
33;Noruega
207;Nueva Caledonia
208;Nueva Zelanda
192;Omán
171;Pakistán
209;Palau
75;Panamá
210;Papua Nueva Guinea
91;Paraguay
92;Peru
200;Polinesia Francesa
34;Polonia
35;Portugal
76;Puerto Rico
193;Qatar
45;Reino Unido
105;Rep. Centroafricana
11;Rep. Checa
63;Rep. Dominicana
134;Ruanda
36;Rumania
37;Rusia
147;Sáhara Occidental
211;Samoa
38;San Marino
135;Sao Tomé y PrÃncipe
136;Senegal
137;Seychelles
138;Sierra Leona
173;Singapur
220;Siria
139;Somalia
175;Sri Lanka
78;St. Vicent y Grenadines
77;St.Kitts & Nevis
141;Sudán
41;Suecia
42;Suiza
93;Sur Georgia e I. Sandwich
140;Suráfrica
94;Surinam
142;Swazilandia
178;Tailandia
176;Taiwán
177;Tajikistán
143;Tanzania
144;Togo
213;Tonga
79;Trinidad y Tobago
145;Túnez
179;Turkmenistán
43;Turquia
214;Tuvalu
44;Ucrania
146;Uganda
95;Uruguay
180;Uzbekistán
215;Vanuatu
46;Vaticano
96;Venezuela
181;Vietnam
196;Yemen
109;Yibuti
47;Yugoslavia
148;Zaire
149;Zambia
150;Zimbabwe
Other Provinciasespañ±olas(CSV)
15;A CORUÑA/LA CORUÑA
01;ALAVA/ARABA
02;ALBACETE
03;ALICANTE/ALACANT
04;ALMERÃA
33;ASTURIAS
05;AVILA
06;BADAJOZ
08;BARCELONA
09;BURGOS
10;CÃCERES
11;CÃDIZ
39;CANTABRIA
12;CASTELLÓN/CASTELLÓ
51;CEUTA
13;CIUDAD REAL
16;CUENCA
14;CÓRDOBA
17;GIRONA/GERONA
18;GRANADA
19;GUADALAJARA
20;GUIPUZKOA/GUIPÚZCOA
21;HUELVA
22;HUESCA
07;ILLES BALEARS/I. BALEARES
23;JAÉN
26;LA RIOJA
35;LAS PALMAS
24;LEÓN
25;LLEIDA/LÉRIDA
27;LUGO
29;MÃLAGA
28;MADRID
52;MELILLA
30;MURCIA
31;NAVARRA
32;OURENSE/ORENSE
34;PALENCIA
36;PONTEVEDRA
37;SALAMANCA
40;SEGOVIA
41;SEVILLA
42;SORIA
38;STA CRUZ DE TENERIFE
43;TARRAGONA
44;TERUEL
45;TOLEDO
46;VALENCIA
47;VALLADOLID
48;VIZCAYA/BIZKAIA
49;ZAMORA
50;ZARAGOZA