Skip to content

Instantly share code, notes, and snippets.

@tit
tit / set_sensitivity.ts
Last active Feb 1, 2021
Create AntiFool Button
View set_sensitivity.ts
function setSensitivity(element: HTMLElement, callback: () => void, timeout: number = 500): void {
let sensitivityTimer: number;
element
.addEventListener('mousedown', () => {
sensitivityTimer = setTimeout(callback, timeout);
});
element
.addEventListener('mouseup', () => {
@tit
tit / swing_lesson_generator.html
Last active Jan 21, 2020
Swing Lesson Generator
View swing_lesson_generator.html
<head>
<meta charset="utf-8">
<script>
const notes = [
'<note applicature="left">♪</note>',
'<note applicature="kick">♪</note>',
'<pause>.</pause>'
];
View note_generator.rb
notes = %w[ .]
4.times do
3.times do
measures = []
4.times do
measures.push "#{notes.sample}.#{notes.sample} #{notes.sample}.#{notes.sample} #{notes.sample}.#{notes.sample} #{notes.sample}.#{notes.sample} | "
end
puts measures.join
end
View case_uri_regexp.rb
# frozen_string_literal: true
url_string = 'https://example.com/foo'
url_object = URI url_string
# false
puts case url_object
when %r{^https://example\.com}
true
else
View just_a_fun.rb
def print string
puts string
end
def to string
string
end
def console string
string
@tit
tit / numeric.rb
Created Nov 2, 2018
Convert numeric to formatted string with cash unit by format
View numeric.rb
# frozen_string_literal: true
# Numeric
class Numeric
# convert numeric (integer or float)
# to formatted string with cash unit
#
# @example
# 42_000.to_cash '$', ',', '.', '%<unit>s%<amount>.2f' # => $42.000,00
# 42_000.42.to_cash 'RUB', ',', ' ', '%<amount>.2f %<unit>s' # => 42 000,42 RUB
@tit
tit / calltools.rb
Last active Sep 1, 2018
CallTools API Client
View calltools.rb
# http-cookie need for Max-Age
# @see https://github.com/nahi/httpclient/issues/242#issuecomment-69020815
require 'http-cookie'
require 'httpclient'
require 'json'
require 'symbolize_keys_recursively'
# CallTools
module CallTools
# CallTools API Client
@tit
tit / coin.rb
Created Jun 1, 2017
To toss a coin and execute the code ... or not ...
View coin.rb
# execute yield or not
# @return [Mixed]
# @example coin { Hamlet.new.to_be }
def coin
yield if [true, false].sample
end
@tit
tit / sleep.js
Created Jun 21, 2015
Sleep in JS
View sleep.js
Number.prototype.times = function (cb) { for (var i = 0; i < +this; i++) {cb(i)} }
function sleep(ms) {var date = Date.now(); while (Date.now() - date < 1000*ms) {} }
/* example use/*
10..times(function(i){sleep(1); console.log(i);})
@tit
tit / typograf.rb
Last active Aug 29, 2015
Typograf
View typograf.rb
# encoding: utf-8
require 'unirest'
class String
def typograf
api_uri = 'http://www.typograf.ru/webservice/'
begin
response = Unirest.post api_uri, parameters: {text: self}
response.body