This file contains hidden or 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
| shout = "En Taro Tassadar!" | |
| print shout |
This file contains hidden or 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
| my $outer = "outer"; | |
| if (1) { | |
| print $outer . "\n"; | |
| my $inner = "inner"; | |
| } | |
| print $inner . "\n"; | |
| __END__ |
This file contains hidden or 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
| module MyProject | |
| class Wallet | |
| # 省略 | |
| end | |
| end | |
| # 他で Wallet って名前使われても MyProject って prefix があるので競合しない | |
| wallet = MyProject::Wallet.new | |
| wallet.put 10000 | |
| puts wallet.get_balance # => 10000 |
This file contains hidden or 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
| # ポケットモジュールを定義 | |
| module Pocket | |
| def insert_card(card) | |
| if @pocket | |
| raise "already exist in pocket" | |
| end | |
| @pocket = card | |
| end |
This file contains hidden or 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
| # 普通の class 定義 | |
| class Wallet | |
| def initialize | |
| @amount = 0 | |
| end | |
| def put(money) | |
| @amount += money | |
| end |
This file contains hidden or 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 re | |
| regexp = re.compile(r"""\A \s+ # 空白スペース | |
| hoge # hoge に続いて | |
| \s # 空白スペース一個挟んだあと | |
| (.*)\Z # 最後までをマッチする | |
| """, re.X|re.M|re.S) | |
| print regexp.match(" hoge\nabc").groups() # => ('abc',) |
This file contains hidden or 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
| class Client(models.Model): | |
| class Meta: | |
| unique_together = (('email', 'other_field'),) |
This file contains hidden or 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 -*- | |
| from django.core.exceptions import ValidationError | |
| from django.forms.fields import Field, CharField, IntegerField | |
| from jcconv import * | |
| class HiraganaFiled(CharField): | |
| """ | |
| >>> h = HiraganaFiled() | |
| >>> 'ひらがなはんかく' == h.to_python('ヒラガナハンカク') |
This file contains hidden or 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
| use strict; | |
| use warnings; | |
| use utf8; | |
| use File::Find; | |
| use IO::File; | |
| File::Find::find({ wanted => \&wanted, no_chdir => 1}, '.'); | |
| sub wanted { |
This file contains hidden or 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
| from apps.appname.models import Receivable | |
| from django.db.models import Sum | |
| receivable = Receivable.objects.all() | |
| receivable.query.group_by = ['client_id'] | |
| receivable.annotate( total_price = Sum('price') ) |