Skip to content

Instantly share code, notes, and snippets.

View st98's full-sized avatar

st98 st98

View GitHub Profile
@st98
st98 / check.sql
Last active August 29, 2015 14:14
check 制約。
create table t (a int check(a > 5));
insert into t values (1); -- Error: CHECK constraint failed: t
-----
create table a(x int);
insert into a values ('hoge');
insert into a values (5);
select * from a; -- hoge 5
-----
create table b(x int check(typeof(x) is 'integer'));
insert into b values ('hoge'); -- Error: CHECK constraint failed
@st98
st98 / with.sql
Last active August 29, 2015 14:14
with 節。
create table t(n int, s text, t text);
insert into t values (1, 'abc', 'hoge');
insert into t values (2, 'def', 'fuga');
with s(a, b, c) as (select * from t) select * from s;
@st98
st98 / fizzbuzz.sql
Last active August 29, 2015 14:14
SQL で FizzBuzz。
with recursive t(x, s) as (
select 0, NULL union all select x + 1,
case
when (x + 1) % 15 = 0 then 'FizzBuzz'
when (x + 1) % 3 = 0 then 'Fizz'
when (x + 1) % 5 = 0 then 'Buzz'
else (x + 1)
end
from t limit 1, 100
) select s from t;
create table s (x int, y int);
insert into s values (2, 2), (1, 3), (1, 1), (2, 1), (3, 1);
-- 普通の使い方
select y from s; -- 2 3 1 1 1
select * from s; -- 2|2 1|3 1|1 2|1 3|1
select y from s order by y; -- 1 1 1 2 3
select * from s order by x; -- 1|3 1|1 2|2 2|1 3|1
select * from s order by y; -- 1|1 2|1 3|1 2|2 1|3
<!doctype html>
<html>
<head>
<title>marquee</title>
</head>
<body>
<a href="https://gist.github.com/st98/0ac9abdddb1f09d0a50d">source</a>
<script>
var t = document.getElementsByTagName('title')[0].firstChild;
var s = t.nodeValue, i = 0;
@st98
st98 / r.js
Created February 6, 2015 21:49
f('hoge', 3) === 'ehog';
function f(s, n) {
n %= s.length;
return s.slice(n) + s.slice(0, n);
}
function g(s, n) {
n %= s.length;
return (s + s).slice(n, n + s.length);
}
function h(s, n) {
var r = '';
<!doctype html>
<html>
<head>
<title>x-marquee</title>
</head>
<body>
<p><x-marquee>marquee</x-marquee> | <x-marquee>marquee</x-marquee></p>
<a href="https://gist.github.com/st98/0fff653a504d8a5627fc">source</a>
<script>
document.registerElement('x-marquee');
@st98
st98 / delete.js
Created February 18, 2015 10:13
delete。
function C() {}
C.prototype.m = function () { return 'm'; };
/////
var a = new C();
a.m(); // => 'm'
/////
delete a.m;
a.m(); // => 'm'
/////
delete C.prototype.m;
b = /b/
#####
/a#{b.source}c/.source # => 'a#{b.source}c'
///a#{b.source}c///.source # => 'abc'
@st98
st98 / nicos.js
Last active August 29, 2015 14:16
ニコニコ動画のマイリストの合計再生時間を出力するヤツ。
(function () {
if (!(String.prototype.repeat)) {
String.prototype.repeat = function (n) {
if (n < 0) throw RangeError('Invalid repeat count');
return Array(n + 1).join(this);
};
}
function zfill(s, n) {
if (s.length >= n) return s;
return ('0'.repeat(n) + s).slice(-n);