2019年4月1日月曜日

python basic

x = 3
y = 4
z = 5

x, y, z = 3, 4, 5

my_height = 58

x = int(4.7)   # x is now an integer 4
y = float(4)   # y is now a float of 4.0
>>> print(type(x))
int
>>> print(type(y))
float

String

>>> first_word = 'Hello'
>>> second_word = 'There'
>>> print(first_word + second_word)

HelloThere

>>> print(first_word + ' ' + second_word)

Hello There

>>> print(first_word * 5)

HelloHelloHelloHelloHello

>>> print(len(first_word))

5

>>> first_word[0]

H

>>> first_word[1]

e

print("Mohammed has {} balloons".format(27))
# Mohammed has 27 balloons

new_str = "The cow jumped over the moon."
new_str.split()
# ['The', 'cow', 'jumped', 'over', 'the', 'moon.']

new_str.split(' ', 3)
# maxsplit is set to 3, ['The', 'cow', 'jumped', 'over the moon.']

List

list_of_random_things = [1, 3.4, 'a string', True]
>>> list_of_random_things[-1]
True
>>> list_of_random_things[-2]
a string

When using slicing, it is important to remember that the lower index is inclusive and the upper index is exclusive.

>>> 'isa' in 'this is a string'
False
>>> 5 not in [1, 2, 3, 4, 6]
True

name = "-".join(["García", "O'Kelly"])
print(name)
# García-O'Kelly

letters = ['a', 'b', 'c', 'd']
letters.append('z')
print(letters)
# ['a', 'b', 'c', 'd', 'z']

tuple

location = (13.4125, 103.866667)
print("Latitude:", location[0])
print("Longitude:", location[1])

dimensions = 52, 40, 100
length, width, height = dimensions
print("The dimensions are {} x {} x {}".format(length, width, height))

set

A set is a data type for mutable unordered collections of unique elements.
numbers = [1, 2, 6, 3, 1, 1, 6]
unique_nums = set(numbers)
print(unique_nums)
# {1, 2, 3, 6}

fruit = {"apple", "banana", "orange", "grapefruit"}  # define a set
print("watermelon" in fruit)  # check for element
fruit.add("watermelon")  # add an element
print(fruit.pop())  # remove a random element

dictionary

elements = {"hydrogen": 1, "helium": 2, "carbon": 6}
print(elements["helium"])  # print the value mapped to "helium"
elements["lithium"] = 3  # insert "lithium" with a value of 3 into the dictionary

We can check whether a value is in a dictionary the same way we check whether a value is in a list or set with the in keyword. Dicts have a related method that's also useful, get. get looks up values in a dictionary, but unlike square brackets, get returns None (or a default value of your choice) if the key isn't found.

print("carbon" in elements)
print(elements.get("dilithium"))

Zip

a = [1, 2, 3, 4, 5]
b = [10, 11, 12, 13, 14]
list(zip(a, b)) #[(1, 10), (2, 11), (3, 12), (4, 13), (5, 14)]



2019年2月14日木曜日

php error表示

ini_set('display_errors', "On");
ini_set('error_reporting', E_ALL);

2019年1月24日木曜日

php DateTime diff

DateTime比較するには、diffを使います。

$datetime = new  DateTime("20190101");
$today_dt = new DateTime();
// $datetimeと現在の日付を比較する、$datetime - $today_dt の感じ
$interval = $datetime->diff($today_dt);

どっちが後ろ(大きい)かは、$interval['invert']が1の場合、$datetimeのほうが大きい。

2019年1月19日土曜日

symfony Timestampable

1)StofDoctrineExtensionsBundleをインストール
composer require stof/doctrine-extensions-bundle

2)Activating Timestampable
config
stof_doctrine_extensions:
    default_locale: ja_JP
    orm:
        default:
            timestampable: true

3)Entityに以下追加
<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Gedmo\Timestampable\Traits\TimestampableEntity;

class User implements UserInterface
{
    use TimestampableEntity;
......

4)bin/console make:migration

5)bin/console doctrine:migrations:migrate

2018年12月14日金曜日

css grid vs flex

Grid is Container-Based, Flexbox is Content-Based
This is an important difference. It shows that the flexbox layout is calculated after its content is loaded whereas the grid layout is calculated regardless of the content inside it. So, if possible, avoid using flexbox to build the overall layout of your website.

Grid Has a “Gap” Property, Flexbox Doesn’t

Flexbox is One Dimensional, Grid is Two Dimensional
Flexbox is best for arranging elements in either a single row, or a single column. Grid is best for arranging elements in multiple rows and columns.

Flexbox Wraps vs Grid Wraps
when a flex-item is wrapped and pushed in a new row, the Flexbox layout algorithm treats it as a part of a different flex-container. Hence the pushed item loses its context.

参考:https://www.webdesignerdepot.com/2018/09/grid-vs-flexbox-which-should-you-choose/

2018年8月30日木曜日

frontend validation [native browser form validation]

[Required]
<input type="text" required>

[Length]
<input type="text" minlength="3" maxlength="12">

[Pattern]
<input type="password" pattern="^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?!.*\s).*$" required>
If you provide a title attribute with the pattern, the title value will be included with any error message if the pattern doesn't match.

[Number]
<input type="number" pattern="[-+]?[0-9]">
Browser support for input[type="number"] varies, but you can supply a pattern as a fallback.

<input type="number" step="any" pattern="[-+]?[0-9]*[.,]?[0-9]+">
You can allow floats (numbers with decimals) with the step attribute. This tells the browser what numeric interval to accept. It can be any numeric value (example, 0.1 ), or any if you want to allow any number.
You should also modify your pattern to allow decimals.

<input type="number" min="3" max="42" pattern="[3-9]|[1-3][0-9]|4[0-2]">
If the numbers should be between a set of values, the browser can validate those with the min and max attributes. You should also modify your pattern to match.

[Email]
<input type="email" pattern="^([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22))*\x40([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d))*$">
The email input type will alert users if the supplied email address is invalid. Like with the number input type, you should supply a pattern for browsers that don't support this input type.

[uri]
<input type="url" pattern="^(?:(?:https?|HTTPS?|ftp|FTP):\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-zA-Z\u00a1-\uffff0-9]-*)*[a-zA-Z\u00a1-\uffff0-9]+)(?:\.(?:[a-zA-Z\u00a1-\uffff0-9]-*)*[a-zA-Z\u00a1-\uffff0-9]+)*)(?::\d{2,})?(?:[\/?#]\S*)?$">

[date]
<input type="date" pattern="(?:19|20)[0-9]{2}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9])|(?:(?!02)(?:0[1-9]|1[0-2])-(?:30))|(?:(?:0[13578]|1[02])-31))">
value is actually in this format: YYYY-MM-DD
type="time"  
type="month"


You can style fields that have errors on them with the :invalid pseudo-selector, but you can't style the error messages themselves.
CSS tip: style invalid selectors only when they aren't currently being edited with :not(:focus):invalid { }

参考:https://css-tricks.com/form-validation-part-1-constraint-validation-html/

2018年8月29日水曜日