Skip to content

Instantly share code, notes, and snippets.

View vkgtaro's full-sized avatar
😃

Taro Komatsu vkgtaro

😃
View GitHub Profile
shout = "En Taro Tassadar!"
print shout
@vkgtaro
vkgtaro / scope.pl
Last active December 11, 2015 19:28
my $outer = "outer";
if (1) {
print $outer . "\n";
my $inner = "inner";
}
print $inner . "\n";
__END__
module MyProject
class Wallet
# 省略
end
end
# 他で Wallet って名前使われても MyProject って prefix があるので競合しない
wallet = MyProject::Wallet.new
wallet.put 10000
puts wallet.get_balance # => 10000
# ポケットモジュールを定義
module Pocket
def insert_card(card)
if @pocket
raise "already exist in pocket"
end
@pocket = card
end
# 普通の class 定義
class Wallet
def initialize
@amount = 0
end
def put(money)
@amount += money
end
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',)
class Client(models.Model):
class Meta:
unique_together = (('email', 'other_field'),)
# -*- 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('ヒラガナハンカク')
use strict;
use warnings;
use utf8;
use File::Find;
use IO::File;
File::Find::find({ wanted => \&wanted, no_chdir => 1}, '.');
sub wanted {
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') )