Skip to content

Instantly share code, notes, and snippets.

@bisque33
bisque33 / result.ts
Last active March 18, 2020 09:35
Introduce Result type for server side TypeScript error handling
export type Result<T, E> = Success<T> | Failure<E>
export interface IResult<T, E> {
isSuccess(): boolean
}
export class Success<T> implements IResult<T, never> {
constructor(private value: T) { }
isSuccess(): boolean {
return true
@bisque33
bisque33 / slackCommandProcess.js
Last active August 31, 2016 09:57
Lambda Function that post to slack bot and then some process.
'use strict';
var https = require('https');
var url = require('url');
exports.handler = (event, context) => {
console.log(event);
var user = event.user_name;
var command = event.command;
@bisque33
bisque33 / slackCommandEntry.js
Last active August 31, 2016 09:57
Lambda Function that accepts a slack command and invoke another Lambda with async.
'use strict';
var AWS = require('aws-sdk');
var qs = require('querystring');
var url = require('url');
var https = require('https');
var token, kmsEncyptedToken;
kmsEncyptedToken = "<kmsEncryptedToken>";
@bisque33
bisque33 / gist:7c9465f5fb6954307567
Last active August 29, 2015 14:18
Array#eachを自作する
class Array
def each2
for i in self
yield i
end
end
def each3(&block)
for i in self
block.call i
end
@bisque33
bisque33 / gist:6920780
Last active December 25, 2015 04:59
菱形を書くrubyプログラム
radius = ARGV[0] || 10
radius = radius.to_i
result = []
height = (radius * 2) - 1
height.times do |i|
if i < radius
half = "-" * radius
half[radius - (i + 1)] = "*"
@bisque33
bisque33 / gist:3616301
Created September 4, 2012 03:42
Installing selenium-webdriver on windows
ruby dk.rb init
[INFO] found RubyInstaller v1.9.1 at C:/Ruby191
Initialization complete! Please review and modify the auto-generated 'config.yml' file to ensure it contains the root directories to allof the installed Rubies you want enhanced by the DevKit.
# pikを使っている場合
# C:\Users\[UserName]\.pik\config.yml に記載されているパスを/binを取り除いて
# "193: ruby 1.9.3p125 (2012-02-16) [i386-mingw32]":
# :path: !ruby/object:Pathname
@bisque33
bisque33 / youtuber-sample.rb
Created June 27, 2012 11:10
Rubygem youtuber sample
require 'youtuber'
# developer_key などをセットしてGDataオブジェクトを作成
gdata = YouTubeR::GData.new("<email@google.com>", "<password>", "<developer_key>", "<app_name>")
# search_feeds メソッドでは YoutubeAPI の検索パラメータが使える
# https://developers.google.com/youtube/2.0/reference?hl=ja#Searching_for_videos
# ここで返ってくるのは YoutubeAPIの生のレスポンス
xml_videos_feed = gdata.search_feeds(:q => "git", :orderby => "viewCount", :"max-results" => 10)
require 'rubygems'
require 'test/unit'
require 'shoulda'
require 'mocha'
lib_files = File.join(File.dirname(__FILE__), "..", "lib")
Dir.glob(File.join(lib_files, "**")).each do |file|
require file
end