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
<html> | |
<head> | |
<title>getElementById example</title> | |
<style> | |
table .c { color: red } | |
.a.c {color: green} | |
</style> | |
<script type="text/javascript"> |
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 | |
function checkBraces($str){ | |
$stack = Array(); | |
for ($i = 0; $i < strlen($str); ++$i) { | |
$value = $str[$i]; | |
if ($value == '(' || $value == '{'){ | |
array_push($stack, $value); | |
} else if ($value == ')' || $value == '}'){ | |
if (count($stack) <= 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
=begin rdoc | |
Checks that the supplied date has the correct date format '#YYYY:MM:DD' with the separators both be either - or : or /. | |
A year cannot start from the zero, while a month and a day can. | |
Performs additional checkings that the date is valid. | |
=end | |
def checkDateUpdated(aDate) | |
matched = | |
%r{ | |
(?<year> | |
(^ #no input before the start |
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
=begin rdoc | |
Checks that the supplied date has the correct date format '#YYYY:MM:DD' with the separators both be either - or : or /. | |
A year cannot start from the zero, while a month and a day can. | |
Doesn't check that the supplied day is within the specified month's day range. It may be further improved. | |
=end | |
def checkDate(aDate) | |
%r{ | |
(?<year> | |
(^ #no input before the start | |
[1-9]\d{3} #a year cannot start from the zero |
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 | |
$src = '{Пожалуйста|Просто} сделайте так, чтобы это {удивительное|крутое|простое} тестовое предложение {изменялось {быстро|мгновенно} случайным образом|менялось каждый раз}'; | |
while (preg_match("/\{([^\{\}]*)\}/", $src, $matches)){ | |
$alt_items = explode("|", $matches[1]); | |
$item = $alt_items[array_rand($alt_items)]; | |
$src = str_replace($matches[0], $item, $src); | |
} |
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
import java.text.CharacterIterator; | |
import java.text.StringCharacterIterator; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.Random; | |
import java.util.Stack; | |
public class SentenceMixer { | |
private static class Item { |
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 | |
src = '{Пожалуйста|Просто} сделайте так, чтобы это {удивительное|крутое|простое} тестовое предложение {изменялось {быстро|мгновенно} случайным образом|менялось каждый раз}'; | |
r = Regexp.new(/\{[^\{\}]*\}/) | |
while (match = r.match(src)) do | |
match.length.times { |i| | |
offsets = match.offset(i) | |
chunk = src[offsets[0],offsets[1]-offsets[0]] | |
bracelessChunk = chunk[1..-2] #remove leading '{' and trailing '}' |
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
require 'thread' #taken from http://burgestrand.se/code/ruby-thread-pool/ | |
class Pool | |
def initialize(size) | |
@size=size | |
@jobs = Queue.new | |
@pool = Array.new(@size) do |i| | |
Thread.new do | |
Thread.current[:id] = i | |
catch(:exit) do |
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 ruby | |
require 'open-uri' | |
require 'pool' #taken fron http://burgestrand.se/code/ruby-thread-pool/ | |
IMG_REGEXP = /\<img[^(src)]*src=(\"|\')((http:\/\/)?[\w\.\/:-]+)\1[^\\>]*\\?\>/ | |
VALID_IMAGE_EXTENSION_REGEXP = /.*\.(gif|tif|png|jpeg|jpg)$/ | |
def image_extension_correct?(image) | |
not image.nil? and image =~ VALID_IMAGE_EXTENSION_REGEXP | |
end |
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
require 'benchmark' | |
NUM_PERSONS = 100_000#10_000_000 | |
class Person < Struct.new(:sex, :age, :height, :index, :money) | |
end | |
class Array | |
def search(options={}) | |
options.delete_if {|k,v| not Person.members.include?(k.to_s)} |
NewerOlder