Skip to content

Instantly share code, notes, and snippets.

View st98's full-sized avatar

st98 st98

View GitHub Profile
<!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 / 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>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;
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
@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;
@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 / 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 / a.js
Last active August 29, 2015 14:14
process.stdin, test
function f(s) {
return s.split('').map(function (a) {
return ('00' + a.charCodeAt(0).toString(16)).slice(-2);
}).join(' ');
}
process.stdin.setEncoding('utf8');
process.stdin.on('readable', function () {
var a = process.stdin.read();
if (a !== null) {
console.log('> ', a.replace(/\n/, ''));
@st98
st98 / a.js
Created January 29, 2015 17:44
f('ABCDE') === 'ABCDE'; g('ABCDE') === 'ABCDE';
function f(s) {
return s.replace(/[A-~]/g, function (c) {
return String.fromCharCode(c.charCodeAt(0) + 0xfee0);
});
}
function g(s) {
return s.replace(/[\uff01-\uff5e]/g, function (c) {
return String.fromCharCode(c.charCodeAt(0) - 0xfee0);
});
}
@st98
st98 / p.coffee
Created January 27, 2015 20:05
8 進数。p('1234') === 668。
p = (s) ->
m = s.match /[0-7]+/
if m is null
return NaN
r = 0
for c, i in (m[0].split '').reverse()
n = parseInt c, 10
r += n * Math.pow 8, i
if s[0] is '-' then -r else r