Skip to content

Instantly share code, notes, and snippets.

View tit's full-sized avatar

TIT tit

  • Russia, Rostov-on-Don
View GitHub Profile
@tit
tit / typograf.rb
Last active August 29, 2015 14:16
Typograf
# 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
@tit
tit / sleep.js
Created June 21, 2015 15:32
Sleep in 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);})
bool x = true;
x = x == false; // or x = !x
@tit
tit / realWidthHeight.js
Created June 15, 2013 21:39
Real Width/Height of webpage
Math.max(document.body.clientWidth, document.body.offsetWidth, document.body.scrollWidth);
Math.max(document.body.clientHeight, document.body.offsetHeight, document.body.scrollHeight);
@tit
tit / status.bash
Last active December 19, 2015 16:18
A quick way to get HTTP status
curl -I http://example.com 2> /dev/null | grep HTTP | egrep -o [0-9]{3}
curl -w "%{http_code}" http://example.com 2> /dev/null
@tit
tit / randomizer.bash
Last active December 19, 2015 16:19
Rename images with random name
for i in *.jpg; do mv $i `uuidgen`.jpg; done
@tit
tit / coin.rb
Created June 1, 2017 12:49
To toss a coin and execute the code ... or not ...
# execute yield or not
# @return [Mixed]
# @example coin { Hamlet.new.to_be }
def coin
yield if [true, false].sample
end
@tit
tit / calltools.rb
Last active September 1, 2018 12:39
CallTools API Client
# 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 / numeric.rb
Created November 2, 2018 11:10
Convert numeric to formatted string with cash unit by format
# 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 / just_a_fun.rb
Created November 1, 2019 09:53
just a fun
def print string
puts string
end
def to string
string
end
def console string
string