Skip to content

Instantly share code, notes, and snippets.

@hkdnet
hkdnet / foo.rb
Created September 18, 2017 02:05
p (-1.3).abs
p = 2
p (-1.3).abs
@hkdnet
hkdnet / a.rb
Last active March 4, 2017 08:41
class Mino
# I L O S T
attr_reader :type
def initialize(type)
@type = type
end
def bottoms
case type
when "I"
@hkdnet
hkdnet / main.rb
Last active October 1, 2016 10:56
オフラインリアルタイムどう書くE08(http://mtsmfm.github.io/2016/10/01/doukaku-e08.html) 回答
class Point
include Comparable
attr_accessor :x, :y
def initialize(x, y)
@x = x
@y = y
end
def to_s
"(#{x}, #{y})"
(function() {
let opts = document.querySelectorAll('#templates option');
let filters = [
/* 除外したいオプションの正規表現を何個か書く */
];
[...opts].forEach(e => {
if (filters.some(f => f.test(e.innerText))) {
e.parentElement.removeChild(e);
}
});
@hkdnet
hkdnet / zndk.cs
Last active March 12, 2016 09:45
zndk
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
public class Hello{
public static void Main(){
var rnd = new Random();
var zn = "ズン";
var dk = "ドコ";
var expected = "ズンズンズンズンドコ";
def hoge(a, b, c, e, n)
[a, b, c, e, n].reject(&:nil?).each(&:strip!)
p a
p b
p c
p e
p n
end
hoge("a ", "b ", " c ", "", nil)
@hkdnet
hkdnet / pre-commit
Created October 4, 2015 23:39
.git/hooks/pre-commit
#!/usr/bin/env ruby
if `git branch`.chomp.split("\n").find { |e| e == '* master' }
puts 'ここはmasterブランチ。許可のないやつは通せないぜ > 乂・д・)'
exit false
end
# http://qiita.com/HKDnet/items/57a0630705d3f6468a77
# $Env:MackerelApiKey is needed
function Get-MackerelHosts {
$ret = Invoke-RestMethod -Uri "https://mackerel.io/api/v0/hosts.json" -Headers @{ "X-Api-Key" = $Env:MackerelApiKey }
return $ret.hosts
}
function Get-MackerelServices {
$ret = Invoke-RestMethod -Uri "https://mackerel.io/api/v0/services" -Method GET -Headers @{ "X-Api-Key" = $Env:MackerelApiKey}
@hkdnet
hkdnet / gist:eba6d04327b6a9c63ea1
Last active August 29, 2015 14:23
MockFramework CreateDbSet Pattern
public Mock<DbSet<T>> CreateMockSet<T>(IQueryable<T> src)
where T: class
{
var mockSet = new Mock<DbSet<T>>();
mockSet.As<IQueryable<T>>().Setup(m => m.Provider).Returns(src.Provider);
mockSet.As<IQueryable<T>>().Setup(m => m.Expression).Returns(src.Expression);
mockSet.As<IQueryable<T>>().Setup(m => m.ElementType).Returns(src.ElementType);
mockSet.As<IQueryable<T>>().Setup(m => m.GetEnumerator()).Returns(src.GetEnumerator());
return mockSet;
}