Skip to content

Instantly share code, notes, and snippets.

@dinhhuydh
dinhhuydh / Ruby loop exercises
Created November 30, 2017 03:51
Ruby loop exercises
# 1. Returns the elements at even positions
# a = [5,6,7,3]
# => [5,7] (5 at index 0, 7 at index 2)
# 2. Calculate the fibonaci at n th (1,1,2,3)
# fibonaci(2) => 1
# fibonaci(4) => 3
# 3. Count how many number 4 in array
#1. sum of even numbers
# count_even(a)
# [1,2,3] => 2
# [1,2,4] => 6
# 2. Return names with 'H' at first letter
# ['Haa', 'aa', 'kkk] => ['Haa']
# 1. count number of words in a string
# E.g 1: count_words("this is an object") ==> 4
# 2. Count how many max numbers
# eg1: [3,5,6,3,6] => 2
# eg2: [1,5,6,6,6] => 3
# 3. Find longest string
# eg 1: ['a', 'bbbbb', 'zzz'] => 'bbbb'
# 1 Print square of number from 1 to n
# eg1: squares(3) => [1, 4, 9]
# 2: Print all numbers with 3 digits have two '1' digits like 112, 131
# 3. Calculate sum of digits in the numbers
# eg1: [12, 4, 154] => [3, 4, 10]
# 4. Transform a number to simple word of digits
# eg1: 12 => one two

Principle

  • It does not predict a price up or down
  • It only notify when there is a rise on a coin. Price change is > 1.5% and volume change > 2%
  • It gets data on Poloniex page
  • The bot fetch data every 3 minutes

Examples

Ripple 1.0559% rises vs previous price. Volume: 22.6 btc. 24h Volume: 61960.10461694 btc. Rise streak: 1. Rise percentage (recent 100): 50.5%. Trend: 1.05% -0.73% -0.83% -0.13% -1.88% -1.23% 1.25% 0.63% -1.76% -1.5% . Watch & buy?

  • Rise 1.0559% to previous price in btc
  • Volume: 22.6 btc (estimated, maybe incorrect because Poloniex does not supply)
  • 24h Volume
# added to .git-hooks/pre_commit/debugger.rb
module Overcommit::Hook::PreCommit
# Check for Debugger
class Debugger < Base
def run
keywords = config['keywords']
result = execute(command, args: [keywords.join('|')] + applicable_files)
unless result.stdout.empty?
extract_messages(
## require in .rubocop.yml
require
- ./linters/migration/add_index_name.rb
## config in .hound.yml
ruby:
config_file: .rubocop.yml
module RuboCop
module Cop
module Migration
class AddIndexName < RuboCop::Cop::Cop
# Postgres and MySQL have different naming conventions, so if we need to remove them we cannot predict accurately what the constraint name would be.
MSG = 'Please explicitly name your index or constraint.'.freeze
CONSTRAINT_METHODS = %i{
add_unique_constraint add_constraint add_foreign_key add_index add_primary_key add_full_text_index add_spatial_index
unique_constraint constraint foreign_key index primary_key full_text_index spatial_index
}.freeze
@dinhhuydh
dinhhuydh / bitrix24.rb
Created June 17, 2019 10:22
Create product on Bitrix24 with inbound webhook API
# Resolve errors: Name is not specified
connection = Faraday.new(url: @@base_url)
connection.post do |req|
req.url 'crm.product.add'
req.headers['Content-Type'] = 'application/json'
req.body = { fields: { NAME: product_name, PRICE: estate.gia_khoi_diem, DESCRIPTION: product_description } }.to_json
end
@dinhhuydh
dinhhuydh / gist:0d44b0560c99968496597c3bd79ce754
Last active October 27, 2020 07:05
Install rgeo on ubuntu
# Install dependency
sudo apt install libgeos-3.6.2 libgeos-dev libgeos++-dev libproj-dev libproj12
# Make link to dependency
sudo find / -name 'libgeos*'
sudo ln -s /usr/lib/x86_64-linux-gnu/libgeos-3.6.2.so /usr/lib/libgeos.so
sudo ln -s /usr/lib/x86_64-linux-gnu/libgeos-3.6.2.so /usr/lib/libgeos.so.1
# Clear cache