Skip to content

Instantly share code, notes, and snippets.

c = T.current;
if(c){
s = "[*** " + c + "]"
if(T.range.len){
T("replaceRange", {text:s,
replacingRange:{ loc:T.range.loc, len:c.length },
selectingRange:{ loc:T.range.loc, len:s.length }
} );
}else{
T("replaceCurrent",{text:s});
@ongaeshi
ongaeshi / using_irb_as_a_programmable_calculator.md
Last active January 12, 2021 05:09
irbをプログラマブル電卓として使いこなす

irbをプログラマブル電卓として使いこなす

基本設定

  • .irbrcに設定する
  • ヒストリと補完は必ず動くようにする(複数行編集とかもできるようになるのでRuby 2.7以降がおすすめ)
require 'irb/ext/save-history'
require 'irb/completion'
require 'caseninja'
require 'open-uri'
def get_recent_tracks(token)
URI.open("https://api.spotify.com/v1/me/player/recently-played", "Authorization" => "Bearer #{token}") do |f|
JSON.load(f.read)["items"].map do |e|
e = e["track"]
"#{e["name"]} - #{e["artists"][0]["name"]}"
end
end
end
TOKEN = 'XXXXXXXXXX'
# include <Siv3D.hpp>
// アニメーション描画用のクラス
struct AnimationTexture
{
Array<Texture> textures;
// フレームの時間
Array<int32> delays;
@ongaeshi
ongaeshi / gist:e1feb30f0a9701ab5183b2d4e55ddd1c
Last active December 14, 2020 15:31
bundle exec steep langserver がWindows上で失敗する
PS C:\Users\ongaeshi\Documents\ruby3-test> bundle exec steep langserver
#<ArgumentError: wrong exec option symbol: pgroup>
C:/Ruby30-x64/lib/ruby/3.0.0/open3.rb:221:in `spawn'
C:/Ruby30-x64/lib/ruby/3.0.0/open3.rb:221:in `popen_run'
C:/Ruby30-x64/lib/ruby/3.0.0/open3.rb:160:in `popen2'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/steep-0.38.0/lib/steep/server/worker_process.rb:32:in `spawn_worker'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/steep-0.38.0/lib/steep/drivers/langserver.rb:43:in `run'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/steep-0.38.0/lib/steep/cli.rb:153:in `process_langserver'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/steep-0.38.0/lib/steep/cli.rb:50:in `run'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/steep-0.38.0/exe/steep:11:in `<top (required)>'
# coding: utf-8
require "radiko/radiko"
include Radiko
def c(channel, wday)
Radiko::Radiko.new(channel, last_wday(wday + 1, 1, 0)).astr(channel)
end
def ann(title, wday)
print title, "\n",
#include <Siv3D.hpp> // OpenSiv3D v0.4.3
#include <mruby.h>
#include "mruby/array.h"
#include <mruby/compile.h>
#include <mruby/dump.h>
#include <mruby/string.h>
extern "C" void siv3d_Print(const char* str)
{
# include <Siv3D.hpp> // OpenSiv3D v0.4.3
void Main()
{
const std::array<Texture, 3> textures =
{
Texture(Emoji(U"😊")),
Texture(Emoji(U"😒")),
Texture(Emoji(U"😂")),
};