This file contains 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
# nilの混じった配列 | |
ary = [1,2,3,nil,4,5,6,nil,7,8,9].shuffle | |
## => [2, 6, 3, nil, 4, nil, 5, 1, 8, 9, 7] | |
# 普通に、例えばto_iしてソートすると、nil.to_iは0なので頭の方に固まっちゃう | |
ary.sort_by {|n| n.to_i} | |
## => [nil, nil, 1, 2, 3, 4, 5, 6, 7, 8, 9] | |
# なので、nilの場合にはINFINITYとして扱うようにしてやると、後ろに固められる | |
ary.sort_by{ |i| i || Float::INFINITY} |
This file contains 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
var q = function(){/* | |
SELECT '"' + FB.hogehoge + '","' + FB.fugafuga + '","' + IsNull(ABCD.piyopiyo, ' ') + '"' AS Line | |
FROM FooBar AS FB | |
INNER JOIN ABCDE | |
ON FB.Id = ABCD.foobarId | |
AND ABCD.Name = '$1' | |
AND FB.Active = $2 | |
*/}.toString().split("\n").slice(1,-1).join("\n"); | |
strSQL = q.replace('$1', parameter1) |
This file contains 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
(define (mytimes n val) | |
(if (= n 1) (list val) | |
(append (list val) (mytimes (- n 1) val)))) |
This file contains 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
#include <stdio.h> | |
#include <stdbool.h> | |
#define ZIG 1 | |
#define NONE 0 | |
#define ZAG -1 | |
bool is_zigzag(char* s) { | |
int mode = NONE; | |
char prev = '\0'; | |
for(int i = 0; s[i] != '\0'; i++) { |
This file contains 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
;;---- common-functions ---- | |
(defun filter (pred lst) | |
"引数リストlstの要素の中から、predが成立しない要素を取り除いたリストを返す" | |
(cond ((null lst) nil) | |
((funcall pred (car lst)) | |
(cons (car lst) (filter pred (cdr lst)))) | |
(t (filter pred (cdr lst))))) | |
(defun is_~filep (x) | |
"~が含まれる要素の場合、tを返す" |
This file contains 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
;; Convert DM->second | |
(defun dm-to-sec (x) | |
(* (/ x 100.0) 60.0)) | |
;; Convert DM->minutes | |
(defun dm-to-min (x) | |
(/ x 100.0)) | |
;; Convert second->minutes | |
(defun sec-to-min (x) | |
(/ x 60.0)) | |
;; second->minutes convert with m:s.# style format |
This file contains 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 datetime import datetime as dt | |
def make_time_table(raw_time_table): | |
"""入力された文字から、時間のリストを使って返します""" | |
ret = list() | |
# 1文字目は無意味なので読み捨てます | |
lst = raw_time_table.split(' ')[1:] | |
# 2要素ずつ取り出して、時間データとして確保します |
This file contains 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
def get_timestamp(): | |
from datetime import datetime | |
return datetime.now().strftime('%Y-%m-%d %H:%M') |
This file contains 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
def get_digest(s): | |
import hashlib | |
m = hashlib.md5() | |
m.update(s.encode()) | |
return m.hexdigest() |
This file contains 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
eto = ['申', '酉', '戌', '亥', '子', '丑', '寅', '卯', '辰', '巳', '午', '未'] | |
print('年を入力') | |
y = int(input()) | |
print('干支は{eto}'.format(eto[y%len(eto)])) |
NewerOlder