Symfony 2.1 - Client side validation is only working for required contraint - validation

As the assertions of Entities changed from MinLength and MaxLength to Length, Min and Max to Range, the validator guesser didn't follow these changes and the max_length attribute doesn't get filled, so HTML validation doesn't work for length.
I think there should be a new case for Symfony\Component\Validator\Constraints\Length in guessMaxLengthForConstraint function in Symfony\Component\Form\Extension\Validator\ValidatorTypeGuesser.php
Or is it a solved.
I'm using 2.1.6 but I tried 2.1.7 and there is no difference
Im using this:
/**
* #var float $height
*
* #ORM\Column(name="height", type="decimal", nullable=true)
*
*
* #Assert\Range(
* min = "20",
* max = "96",
* minMessage = "You must be at least 20 tall",
* maxMessage = "You cannot taller than 96"
* )
* #Assert\NotBlank(groups={"registration_step_two","profile_measurement"})
* #Assert\Regex(pattern= "/[0-9]/",message="Require number only")
* #Assert\MinLength(10)
*/

I added group validation to them and its finally work

Related

Ruby, Convert cron range into digit

Using Ruby
I would like that any ranges that appear in a cron to be expanded to the contained numbers in the range ex:
0,5,7,30-35 1,3-8,20 * * * /script.sh
expanded :
0,5,7,31,32,33,34,35 1,3,4,5,6,7,8,20 * * * /script.sh
Any help is appreciated
Assuming that 0,5,7,30-35 1,3-8,20 * * * /script.sh is a string, a simple gsub would work:
str = "0,5,7,30-35 1,3-8,20 * * * /script.sh"
str.gsub(/(\d+)-(\d+)/) { ($1..$2).to_a.join(',') }
#=> "0,5,7,30,31,32,33,34,35 1,3,4,5,6,7,8,20 * * * /script.sh"

Ruby print hash in grid format

I'm working on coding a chess board. The structure of my board will be like this:
# a b c d e f g h
# 1 * * * * * * * * # <= Black pieces on top
# 2 * * * * * * * *
# 3 * * * * * * * *
# 4 * * * * * * * *
# 5 * * * * * * * *
# 6 * * * * * * * *
# 7 * * * * * * * *
# 8 * * * * * * * * # <= White pieces on bottom
I created an #board hash, which stores the value of any item in the grid (i.e. pieces or blank space).
How can I take my hash, which maps a grid location to a "*" currently (i.e. #board['a8']=> '*', etc), and output that hash in the grid-like format?
Here's my #board variable:
def drawBoard
#board = Hash.new
letter='a'
while letter <= 'h'
i=1
while i<9
#board["#{letter}#{i}"] = "*"
i+=1
end
letter=letter.next
end
#board
end
Current output is just the hash itself. i.e.,
{"a1"=>"*", "a2"=>"*", "a3"=>"*", "a4"=>"*", "a5"=>"*", "a6"=>"*", "a7"=>"*", "a8"=>"*", "b1"=>"*", "b2"=>"*", "b3"=>"*", "b4"=>"*", "b5"=>"*", "b6"=>"*", "b7"=>"*", "b8"=>"*", "c1"=>"*", "c2"=>"*", "c3"=>"*", "c4"=>"*", "c5"=>"*", "c6"=>"*", "c7"=>"*", "c8"=>"*", "d1"=>"*", "d2"=>"*", "d3"=>"*", "d4"=>"*", "d5"=>"*", "d6"=>"*", "d7"=>"*", "d8"=>"*", "e1"=>"*", "e2"=>"*", "e3"=>"*", "e4"=>"*", "e5"=>"*", "e6"=>"*", "e7"=>"*", "e8"=>"*", "f1"=>"*", "f2"=>"*", "f3"=>"*", "f4"=>"*", "f5"=>"*", "f6"=>"*", "f7"=>"*", "f8"=>"*", "g1"=>"*", "g2"=>"*", "g3"=>"*", "g4"=>"*", "g5"=>"*", "g6"=>"*", "g7"=>"*", "g8"=>"*", "h1"=>"*", "h2"=>"*", "h3"=>"*", "h4"=>"*", "h5"=>"*", "h6"=>"*", "h7"=>"*", "h8"=>"*"}
Edit:
Thanks to David's answer, he led me toward a much more compact hash generation method as well. The updated (and working) code:
def drawBoard
#board = Hash.new
('a'..'h').each do |letter|
(1..9).each do |i|
#board["#{letter}#{i}"] = "*"
print #board["#{letter}#{i}"]
end
puts
end
end
Provided that you can use symbols for the keys in #board instead of strings:
#board = {:"a1" => "*", ...}
I think the easiest would be to prepare a fixed template string, and do string format to rewrite the grids.
Template = <<_
a b c d e f g h
1 %{a1} %{b1} %{c1} %{d1} %{e1} %{f1} %{g1} %{h1}
2 %{a2} %{b2} %{c2} %{d2} %{e2} %{f2} %{g2} %{h2}
3 %{a3} %{b3} %{c3} %{d3} %{e3} %{f3} %{g3} %{h3}
4 %{a4} %{b4} %{c4} %{d4} %{e4} %{f4} %{g4} %{h4}
5 %{a5} %{b5} %{c5} %{d5} %{e5} %{f5} %{g5} %{h5}
6 %{a6} %{b6} %{c6} %{d6} %{e6} %{f6} %{g6} %{h6}
7 %{a7} %{b7} %{c7} %{d7} %{e7} %{f7} %{g7} %{h7}
8 %{a8} %{b8} %{c8} %{d8} %{e8} %{f8} %{g8} %{h8}
_
Template % #board
If you let #board be a flat array instead (which can be handled by using modulo operations), then replace the %{..} above with %s, and it will work the same way.
Here is a starting point you can use. You would need to add the row and column labels yourself, and add spaces, but this should get you going in the right direction:
('a'..'h').each do |letter|
(1..8).each do |i|
print #board["#{letter}#{i}"]
end
puts # end the line
end

rexx reading file data onto panel

can you please suggest me the manual or example codes on how i can read the content of a file to be displayed in a rexx panel.
the number of lines from the file can vary and so cannot use the static manner.
thanks,
Samuel Mathews.
In ZOS to read the file in rexx use the execio command
i.e.
"EXECIO * DISKR myindd (STEM fileContentsVar."
Reads the file into a stem variable (fileContentsVar.0 holds the number of records and
fileContentsVar.1 ... hold the actual data).
You could store the file contents in a ISPF table and display the table using the
TBDispl command
The rexx code will be roughly
address ispexec
'tbcreate myfile names(line)'
do i=1 to fileContentsVar.0
line = fileContentsVar.i
'tbadd myfile'
end
'tbtop myfile'
'tbdispl mypanel'
'tbend myfile'
For an example of a table-panel definition see http://pic.dhe.ibm.com/infocenter/zos/v1r12/index.jsp?topic=%2Fcom.ibm.zos.r12.f54dg00%2Fispzdg8040.htm
A table-panel would look like:
************************************************************
* )Attr *
* # Type(output) Intens(low) Just(asis) Caps(off) *
* )Body *
* -------------------- ????????????????? ----------------- *
* +Command ==>Cmdfld +Scroll ==>_samt+ *
* + *
* This table shows ... *
* *
* Line *
* )Model * ---- The model setion holds the
* #line + * Table display section
* *
* )Init *
* &samt=page *
* )Proc *
* )End *
************************************************************

Got warning when check whether the credit card number is valid or not

Got this warning when I check whether the credit card number is valid or not. Calling creditcard_helper.php by using the statement if(card_number_valid($this->input->post('card_number'))!=1)
A PHP Error was encountered
Severity: 8192
Message: Function ereg_replace() is deprecated
Filename: helpers/creditcard_helper.php
Line Number: 51
creditcard_helper.php
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* Credit Card Functions
*
* This helper module contains functions which can be used to manipulate credit
* card numbers and related information.
*
* #package CodeIgniter
* #subpackage Helpers
* #category Helpers
* #author Jim O'Halloran
*/
/**
* Truncates a card number retaining only the first 4 and the last 4 digits. It then returns the truncated form.
*
* #param string The card number to truncate.
* #return string The truncated card number.
*/
function truncate_card($card_num) {
$padsize = (strlen($card_num) < 7 ? 0 : strlen($card_num) - 7);
return substr($card_num, 0, 4) . str_repeat('X', $padsize). substr($card_num, -3);
}
/**
* Validates a card expiry date. Finds the midnight on first day of the following
* month and ensures that is greater than the current time (cards expire at the
* end of the printed month). Assumes basic sanity checks have already been performed
* on month/year (i.e. length, numeric, etc).
*
* #param integer The expiry month shown on the card.
* #param integer The expiry year printed on the card.
* #return boolean Returns true if the card is still valid, false if it has expired.
*/
function card_expiry_valid($month, $year) {
$expiry_date = mktime(0, 0, 0, ($month + 1), 1, $year);
return ($expiry_date > time());
}
/**
* Strips all non-numerics from the card number.
*
* #param string The card number to clean up.
* #return string The stripped down card number.
*/
function card_number_clean($number) {
return ereg_replace("[^0-9]", "", $number);
}
/**
* Uses the Luhn algorithm (aka Mod10) <http://en.wikipedia.org/wiki/Luhn_algorithm>
* to perform basic validation of a credit card number.
*
* #param string The card number to validate.
* #return boolean True if valid according to the Luhn algorith, false otherwise.
*/
function card_number_valid ($card_number) {
$card_number = strrev(card_number_clean($card_number));
$sum = 0;
for ($i = 0; $i < strlen($card_number); $i++) {
$digit = substr($card_number, $i, 1);
// Double every second digit
if ($i % 2 == 1) {
$digit *= 2;
}
// Add digits of 2-digit numbers together
if ($digit > 9) {
$digit = ($digit % 10) + floor($digit / 10);
}
$sum += $digit;
}
// If the total has no remainder it's OK
return ($sum % 10 == 0);
}
?>
Please use
preg_replace()
instead of
ereg_replace()
This function has been DEPRECATED as of PHP 5.3.0.
From what you posted, It was not an actual error that occurred, but a warning message, unless your config is setup for error on warnings.
See the ereg_replace documentation.

How do I create a .p12 file in Ruby?

I've looked at the Ruby OpenSSL documentation, but I can't quite figure out the pieces I need to put together to make a .p12 file.
There's also this tutorial, but the comments belie an ambivalence about its correctness.
From ossl_pkcs12.c:
/*
* call-seq:
* PKCS12.create(pass, name, key, cert [, ca, [, key_pbe [, cert_pbe [, key_iter [, mac_iter [, keytype]]]]]])
*
* === Parameters
* * +pass+ - string
* * +name+ - A string describing the key.
* * +key+ - Any PKey.
* * +cert+ - A X509::Certificate.
* * * The public_key portion of the certificate must contain a valid public key.
* * * The not_before and not_after fields must be filled in.
* * +ca+ - An optional array of X509::Certificate's.
* * +key_pbe+ - string
* * +cert_pbe+ - string
* * +key_iter+ - integer
* * +mac_iter+ - integer
* * +keytype+ - An integer representing an MSIE specific extension.
*
* Any optional arguments may be supplied as nil to preserve the OpenSSL defaults.
*
* See the OpenSSL documentation for PKCS12_create().
*/
So (untested and probably incorrect - I am not very familiar with Ruby):
p12 = OpenSSL::PKCS12.create("password", "key", pkey, cert)
p12_bytes = p12.to_der

Resources