Skip to content

Instantly share code, notes, and snippets.

@tokhi
tokhi / go_tutorial.md
Last active July 3, 2023 15:33
Go Tutorial

Go Tutorial

Function Types

Function type is useful:

  • In the case of higher-order functions as we have seen in the above example. The argument and return type is specified using function type
  • In the case of defining interfaces in go as in the interface, only the function type is specified. Whatever implements this interface has to define a function of the same type

Notice that the interface shape only defines the type of function

@tokhi
tokhi / spread.rb
Last active January 7, 2022 19:22
Stock spread option maximum loss and profit calculation
def break_even(long_sp, short_sp, ndp)
if long_sp > short_sp # bear option
long_sp - ndp
else # bull option
long_sp + ndp
end
end
def max_profit(long_sp, short_sp, ndp)
if(long_sp > short_sp) # bear option
@tokhi
tokhi / leads.json
Last active December 18, 2018 17:24
leads.json
[
{
"lead": {
"id": 299888,
"trade_id": 6,
"details": {
"project_deadline": "So schnell wie möglich"
},
"closed_at": null,
"expiration_date": "2018-12-13T01:22:19.000+01:00",
@tokhi
tokhi / aseman_range_to_abi.md
Last active January 26, 2019 21:56
آسمان رنگ تو آبی آبی

آسمان رنگ تو آبی آبی

آسمان دریای پر ز آبی

چه بگویم ز ستاره گانت

که خودت کشور آفتابی

آسمان عاشق مهتابی تو و

@tokhi
tokhi / iterm2-solarized.md
Created February 28, 2017 11:41 — forked from kevin-smets/iterm2-solarized.md
iTerm2 + Oh My Zsh + Solarized color scheme + Meslo powerline font + [Powerlevel9k] - (macOS)

Default

Default

Powerlevel9k

Powerlevel9k

@tokhi
tokhi / add_remove_custom_fields.md
Last active June 21, 2016 15:46
Adding and removing bootstrap custom fields like wordpress.

Adding/removing custom fields

Add and remove bootstrap custom fields by single clicks

index.html file:

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" 
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" 
<link rel="stylesheet" href="scripts/main.js" 
@tokhi
tokhi / vela2.rb
Last active April 15, 2016 09:40
v = Vela::DB.new
v.src_connection(user: 'user', password: 'pass', host: '127.0.0.1', database: 'testpdb', adapter: 'postgresql')
v.dst_connection(user: 'root', password: 'pass', host: '127.0.0.1', database: 'testdb', adapter: 'mysql')
v.dbsync("src_tbl", "dst_tbl") # destination table should already been exist
# if your destination tables' columns are different than the source table (e.g; clonse `col1` data to m_col1 column):
v.dbsync("your_src_tbl", "your_dst_tbl", {"col1" => "m_col1", "col2" => "m_col2"}) # you can add as much as column as you want
@tokhi
tokhi / vela.rb
Last active April 15, 2016 09:40
v = Vela::DB.new
v.src_connection(user: 'root', password: 'pass', host: '127.0.0.1', database: 'testdb', adapter: 'mysql')
v.dst_connection(user: 'user', password: 'pass', host: '127.0.0.1', database: 'testpdb', adapter: 'postgresql')
v.dbsync("src_tbl", "dst_tbl") # destination table should already been exist
# if your destination tables' columns are different than the source table (e.g; clonse `col1` data to m_col1 column):
v.dbsync("your_src_tbl", "your_dst_tbl", {"col1" => "m_col1", "col2" => "m_col2"}) # you can add as much as column as you want
@tokhi
tokhi / ruby_tips.md
Last active April 1, 2016 12:13
Some cool ruby tips and tricks...
@tokhi
tokhi / buergerbot.rb
Last active November 25, 2023 12:01 — forked from pbock/buergerbot.rb
Bürgerbot: Refreshes the Berlin Bürgeramt page until an appointment becomes available, then notifies you.
#!/usr/bin/env ruby
# make sure you the watir gem installed -> gem install watir
require 'watir'
def log (message) puts " #{message}" end
def success (message) puts "+ #{message}" end
def fail (message) puts "- #{message}" end
def notify (message)
success message.upcase
system 'osascript -e \'Display notification Burgerbot with title "%s"\'' % message
rescue StandardError => e