Skip to content

Instantly share code, notes, and snippets.

<?
function genRandomAndReadableString($numberOfLetters)
{
for ($letter = 1, $string = '', $letters = 'aeioubcdfghjlmnpqrstvxz'; $letter <= $numberOfLetters; $letter++)
{
$string .= $letters[($letter % 2 ? rand(5,22) : rand(0,4))];
['give you up', 'let you down', 'run around and desert you', 'make you cry', 'say goodbye', 'tell a lie and hurt you'].each do |n| puts "Never gonna " + n end
range(N) -> range([N-1], N-2).
range(Lista, -1) -> Lista;
range(Lista, N) -> range([N] ++ Lista, N-1).
<?
function get_the_stuff ($string){
preg_match('/"div-([^"]+)"/', $string, $match);
return $match[1];
}
<?
$str = "{ id: 'div-2340796981343853667',
site: '07472483417241913304' },";
function get_that_stuff ($string){
preg_match("/site: '([^']+)'/", $string, $match);
// [^']+ serve pra casar os caracteres que não sejam aspas simples.
// os parênteses são grupos de captura. O que casar com o que estiver dentro das aspas será gravado no $match
return $match[1];
// o 1 é somente o que está dentro do grupo de captura. O que está em 0 é "site: '07472483417241913304'" que é o que minha expressão regular bateu
@pedromenezes
pedromenezes / HTTPServer.rb
Created April 24, 2010 15:53
WebSocket Chat with Node.JS and Sinatra
require 'rubygems'
require 'sinatra'
get '/' do
'
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
</head>
setopt prompt_subst
autoload -Uz vcs_info
autoload -U compinit
#autoload colors
autoload -U promptinit
compinit
promptinit
#colors
<style type="text/css">
/* default link and visited state to trigger :active in IE6 */
a, a:visited {color:#000;}
/* position the outer frame */
div.frame {position:relative; margin:20px auto; width:500px; height:380px; border:1px solid #000;}
/* Set up the default links for the gallery */
div.frame a, div.frame a:visited {background:#eee; text-decoration:none;}
# ab -n 500 -c 30 http://127.0.0.1:4567/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 127.0.0.1 (be patient)
Server Software: WEBrick/1.3.1
<select id="" style="width:300px;height:300px">
<optgroup label="Heróis">
<option value="1">He-man</option>
<option value="5">Gorpo</option>
<option value="3">Mentor</option>
</optgroup>
<optgroup label="Heroínas">
<option value="2">Teela</option>
<option value="4">Feiticeira</option>
</optgroup>