Skip to content

Instantly share code, notes, and snippets.

View 10nin's full-sized avatar
🔥
真空に火を点ける

10nin 10nin

🔥
真空に火を点ける
View GitHub Profile
@10nin
10nin / clocks.lisp
Created July 26, 2017 13:46
xyzzyでつけている勤怠メモから、所定の書式に従って出退勤時間を取り出すスクリプト
;;---- 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を返す"
@10nin
10nin / zigzag.c
Created May 2, 2018 17:00
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0570 この問題に出てくるような、ジグザグ数を探すというのをC言語でやってみた感じのやつ。
#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++) {
@10nin
10nin / mytimes.scm
Created July 11, 2018 12:28
scheme script for (mytimes 5 'foo) → (foo foo foo foo foo) I want more good solution.
(define (mytimes n val)
(if (= n 1) (list val)
(append (list val) (mytimes (- n 1) val))))
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)
# 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}