2014-04-01ãã1ã¶æéã®è¨äºä¸è¦§
CodeEval
CodeEval
çããç±(38度)ãã§ãã
CodeEval
cè¨èªã®ç·´ç¿CodeEval
ããã¥ã¡ã³ãã«ããã¨ä»¥ä¸ã®éããpasswodã¯ããã·ã¥åãããã®ãæå®ããã¨ãã ansible all -m user -a "name=foo password=<crypted password here>" ããã·ã¥åãããã¹ã¯ã¼ãã®ä½ãæ¹ã¯examplesã®user_commads.ymlã«ã³ã¡ã³ãã¨ãã¦æ¸ãã¦ãã https://github.com/ansible/ansib</crypted>â¦
context_dataã«è¾æ¸ã渡ããã¦ãã¦ããã³ãã¬ã¼ãã§ã¢ã¯ã»ã¹ããä¾views.py from django.views.generic import TemplateView class HomeView(TemplateView): template_name = 'sample/home.html' def get_context_data(self, **kwargs): ctx = super(HomeVieâ¦
é©å½ã«ä½ã£ããµã³ãã« from django.views.generic import ListView from items.forms import ItemSearchForm from items.models import Item class ItemListView(ListView): model = Item paginate_by = 10 def __init__(self, **kwargs): super(ItemListVieâ¦
ModelChoiceFieldã®é¸æè¢ãåçã«å¤ãããã¨ãã__init__ã§self.fieldsãåç §ãã¦å ¥ãæ¿ãããã¨ãã§ãã class SelectForm(forms.Form): item = forms.ModelChoiceField(queryset=Item.objects.none()) def __init__(self, category, *args, **kwargs): suâ¦
ä»æ¥ã¯djangoã®method_decoratorã使ãæ©ä¼ããã£ãã®ã§ã½ã¼ã¹ãèªãã§ããã Django Utils | Django documentation | Django djangoã®Class Based Viewã«login_requiredãcsrf_protectãªã©ã®é¢æ°ãã³ã¬ã¼ã¿ããããããã«ç¨æãã¦ããããã ã Introductionâ¦
CodeEvalé¢é£ : python2ã§CodeEvalã®DATA RECOVERY - brainstorm
CodeEval
webéçºæ¡ä»¶ã§ã¯ãã¢ããªãåºåããç»é¢ã®ã¤ã¡ã¼ã¸ã顧客ããhtmlã§æä¾ããããã¨ããããä¸æ¹ãdjangoã®Formã©ã¤ãã©ãªã¯formé¨åã®htmlãåºåãããã¨ãã§ãããã顧客æä¾ã®htmlã¨ä¸è´ããªãã±ã¼ã¹ã¯ããããã¨æãã ãããªãµãã«ãããã°æ¥½ãªãã ãã©â¦
CodeEvalé¢é£ : Python2ã§CodeEvalã®Working Experience - brainstorm
CodeEval
martini-contribã«gzipãç¨æããã¦ãããmartini-contrib ãã ãAccept-Encodingã«gzipãå«ã¾ãã¦ããã°ç¡æ¡ä»¶ã§gzipããã®ã§ãå°ããã³ã³ãã³ããè¿ãã¨ãã¯ä½è¨ã«ãµã¤ãºã大ãããªã£ã¦ãã¾ãã djangoãè¦ã¦ã¿ãããdjango.middleware.gzip.GZipMiddlewarâ¦
é¢é£ : Python2ã§1ç§ãã¨ã®ã¡ã½ããå¼ã³åºãåæ°ãå¶éãããã³ã¬ã¼ã¿ - brainstorm goã ã¨time.Tickã§ãæå®ããééã§ã¡ãã»ã¼ã¸ãåãåããã¨ãã§ããã®ã§ããããªå½¢ã§ã§ããã
reflect.TypeOf㧠package main import ( "fmt" "reflect" ) func main() { fmt.Println(reflect.TypeOf(1)) // int fmt.Println(reflect.TypeOf("")) // string fmt.Println(reflect.TypeOf([]string{})) // []string fmt.Println(reflect.TypeOf(true)) //â¦
ãã¼ã§ã½ã¼ããã¦ãå¤ã¯ã¨ã¹ã±ã¼ããã package main import ( "fmt" "net/url" "sort" "strings" ) type SortedQuery struct { _map map[string]string keys []string } func (sq *SortedQuery) Len() int { return len(sq._map) } func (sq *SortedQuery) â¦
HMACã§ããã·ã¥å¤ãçæãã¦base64ã¨ã³ã³ã¼ããã¦urlã¨ã¹ã±ã¼ãããã amazon product apiã§signatureã¨ãã¦ä½¿ãããå¤ãpython2 import hmac import urllib from hashlib import sha256 from base64 import b64encode key = "key" data = "data" digest = hâ¦
python time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()) golangã®ãã©ã¼ãããæå®ã¯ã¡ãã£ã¨å¤ãã£ã¦ãgolang package main import ( "fmt" "time" ) func main() { now := time.Now().UTC() fmt.Println(now.Format("2006-01-02T15:04:05Z")) } timeâ¦
é¢é£ï¼Python2ã§2ã¤ã®æ¥ä»éã®ææ°ãåå¾ãã - brainstormgoã§ãæ¸ãã¦ã¿ãã Duration使ã£ã¦ãã§ããã package main import ( "fmt" "time" ) // get months between two dates. func MonthDiff(d1, d2 time.Time) int { if d2.After(d1) { d1, d2 = d2, â¦
def diff_month(d1, d2): """ get months between two dates. >>> from datetime import date >>> diff_month(date(2012, 12, 1), date(2013, 3, 1)) 3 """ if d1 > d2: d1, d2 = d2, d1 return (d2.year - d1.year)*12 + d2.month - d1.month datetime - Beâ¦
é¢é£ : python2ã§ãªã¹ããnåãã¤ã®ãµããªã¹ãã«åå²ãã - brainstorm package main import "fmt" func Chunks(l []int, n int) chan []int { ch := make(chan []int) go func() { for i := 0; i < len(l); i += n { from_idx := i to_idx := i + n if to_iâ¦
codeevalã®sudokuãã£ãã¨ãã«èª¿ã¹ãã®ã§ã¡ã¢ã çµå±ä½¿ããªãã£ããã©ãPython2ã§CodeEvalã®SUDOKU - brainstorm # coding=utf-8 size = 4 digits = [1, 4, 2, 3, 2, 3, 1, 4, 4, 2, 3, 1, 3, 1, 4, 2] # ãªã¹ãå å è¡¨è¨ print [digits[x:x + size] for x inâ¦
é¢é£ : Python2ã§CodeEvalã®SUDOKU - brainstorm
CodeEvalãµã¤ãºã¨æ°åã渡ãããããµã¤ãºã¯4ã9ã§ããã 4ã®å ´åã¯4*4=16ã9ã®å ´åã¯9*9=81ã®æ°åããµã¤ãºã«ç¶ãã¦æ¸¡ãããã渡ãããæ°åã®ä¸¦ã³ãæ°ç¬ã®çãã¨ãã¦æç«ãã¦ãããã©ãããTrue or Falseã§åºåããinput 4;1,4,2,3,2,3,1,4,4,2,3,1,3,1,4,2 4â¦
QuerySetã§ã¡ãã£ã¨è¤éãªæ¡ä»¶ãæ¸ãã¦ãã¨ãã¨ããsqlãã©ããªã£ã¦ãã®ã確èªãããå ´åãããã ãããªã¨ãã¯django-extensionsã®shell_plusã®--print-sqlãªãã·ã§ã³ã使ãã¨ä¾¿å©ã ã¢ãã«ãpreloadãã¦ãããã®ã§ãã¡ãã¡importããªãã¦ãã python managâ¦
é¢é£ : Python2ã§CodeEvalã®SUM TO ZERO - brainstorm CodeEval åè¡ã«ã«ã³ãåºåãã§ãããã¤ãæ°åã渡ãããã 4ã¤ãã¤ã®çµã¿åãããä½æãããã®ãã¡åã0ã«ãªãçµã¿åããã®æ°ãåºåãããinput 2,3,1,0,-4,-1 0,-1,3,-2output 2 1