Skip to content

Instantly share code, notes, and snippets.

View aflag's full-sized avatar

Rafael C. de Almeida aflag

View GitHub Profile
@aflag
aflag / gist:3483759
Created August 26, 2012 21:40
How to make tournament visible inside of code ...?
(define-syntax (define-action-with-tournament stx)
(syntax-case stx ()
((_ action-name code ...)
#'(define (action-name request id)
(let ((tournament (tournament/find id)))
(if tournament
(begin code ...)
(v/not-found)))))))
validates :site,
:format => {
:presence => false,
:with => /\b(([\w-]+:\/\/?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|\/)))/,
:message => "Invalid URL"
}
@aflag
aflag / gist:4525333
Last active December 11, 2015 01:39
I am having a hard time trying to write this view. A user has many lawyers and a lawyer can take many services. I want a checkbox which the user can select the services of each lawyer. How can I do it?
<%= form_for @user do |f| %>
<%= f.label :email %><%= f.email_field :email %>
....
<% @user.lawyers.each do |lawyer| %>
<%= f.fields_for :lawyers, lawyer do |lf| %>
<%= lf.label :name, "Nome: " %><%= lf.text_field :name %>
<!-- Everything is working fine so far. However, I can get this to work. A lawyer can have many services: -->
<% Service.all.each do |service| %>
<%= check_box_tag ???, service.id, lawyer.services.include?(service) %>
<% end %>
@aflag
aflag / gist:4780225
Last active December 12, 2015 13:39
class Lawyer < ActiveRecord::Base
def extracted?
!source.blank?
end
with_options :unless => :extracted? do |lawyer|
lawyer.validates_presence_of :oab,
:phones,
:address,
@aflag
aflag / gist:5573543
Created May 14, 2013 03:50
@contact.errors.messages prints one thing before the form_for block, and another thing after.
<% first_lawyer = @contact.lawyers.first %>
<h1 class="g-title">Contato: <%= first_lawyer.name %></h1>
<%= @contact.errors.messages %> <!-- prints {:sender_name=>["não pode ficar em branco"]} -->
<%= form_for(@contact) do |f| %>
<div class="g-form-label">
Advogado:
</div>
<div class="g-block-div">
<%= first_lawyer.name %>
</div>
app = Flask(__name__)
app.config.from_object('yourapplication.default_settings')
app.config.from_envvar('YOURAPPLICATION_SETTINGS')
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
tr {
background-color: red;
height: 30px;
}
</style>
</head>
import Data.List
data BloodType = BloodA | BloodB | BloodAB | BloodO deriving (Eq, Show)
data Gene = A | B | O deriving (Eq, Show, Ord)
type Genes = [Gene]
allGenes = [A, B, O]
possibleGenesByBlood :: BloodType -> [Genes]
possibleGenesByBlood BloodA = [[A, O], [A, A]]
{
"title": "Interatividade",
"services": {
"query": {
"list": {
"0": {
"id": 0,
"type": "topN",
"query": "*",
"alias": "",
nextPos :: Grid -> Movement -> (Int, Int) -> (Int, Int)
nextPos grid GoLeft (x,y)
| inRange (bounds grid) (x-1,y) = (x-1,y)
| otherwise = (x,y)
nextPos grid GoRight (x,y)
| inRange (bounds grid) (x+1,y) = (x+1,y)
| otherwise = (x,y)
nextPos grid GoUp (x,y)
| inRange (bounds grid) (x,y+1) = (x,y+1)
| otherwise = (x,y)