https://github.com/kossnocorp/.bin
https://github.com/kossnocorp/.bin
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/kossnocorp/.bin
- Owner: kossnocorp
- Created: 2013-05-02T20:26:55.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2013-06-21T06:41:39.000Z (almost 12 years ago)
- Last Synced: 2024-12-31T20:43:02.541Z (4 months ago)
- Size: 104 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# .bin
Becoming craftsman.
## Installation
``` sh
export PATH=~/.bin:$PATH
mkdir ~/.bin
echo "echo 'Hello world'" > ~/.bin/hello_world
echo "#\!/bin/sh\necho 'Hello world\!'" > ~/.bin/hello_world
chmod +x ~/.bin/hello_world
hello_world
#=> Hello world!
```## Using symlinks
Looking for easy way to add bin's into PATH?
``` sh
ln -s $(pwd)/bin/coffee ~/.bin/rcoffee
chmod +x ~/.bin/rcoffee
rcoffee
#=> coffee>
```## We need to go deeper
Let's create script for making symlinks (`~/.bin/binl`):
``` ruby
#!/usr/bin/env rubyrequire 'rubygems'
require 'main'Main {
def run
path = ARGV[0]
bin_name = ARGV[1] || ARGV[0].match(/([^\/]+)$/)[1]
bin_path = "~/.bin/#{bin_name}"
`ln -s $(pwd)/#{path} #{bin_path}`
`chmod +x #{bin_path}`
puts "Done, now you can run #{bin_name}"
end
}
```Now you can:
``` sh
binl ./bin/coffee
which coffee
#=> /Users/koss/.bin/coffee
```... or:
``` sh
binl ./bin/coffee coffee_redux
which coffee_redux
#=> /Users/koss/.bin/coffee_redux
```## Advanced example of usage
Like pomodoro technique? Awesome, me too. Let's build our own pomodoro timer.
### Preparing
Let's create blank ruby script (`~/.bin/pomo`):
``` ruby
#!/usr/bin/env ruby
puts 'Hello world!'
```Make it executable:
``` sh
chmod +x ~/.bin/pomo
```### Let's write some code
We need to write prototype for 5 minutes. Let's do it:
``` ruby
#!/usr/bin/env rubyrequire 'rubygems'
require 'main'MINUTES = 60
Main {
def run
while true
puts 'Lets work!'
rules.each do |rule|
puts rule[:title]
rule[:minutes] do |minutes_pass|
minutes_left = rule[:minutes] - minutes_pass
puts "#{minutes_left} left"
sleep MINUTE
end
end
end
enddef rules
[{ title: "Let's work", minutes: 25 },
{ title: "Let's rest", minutes: 5 }]
end
}
```### Improve it
Now things get compicated:
``` ruby
#!/usr/bin/env rubyrequire 'rubygems'
require 'main'
require 'talks'MINUTE = 60
class Timer
class << self
def start!(minutes, &draw)
minutes_left = minuteswhile minutes_left > 0 do
draw.call(minutes_left) if block_given?
minutes_left -= 1
sleep MINUTE
end
end
end
endMain {
def run
while true
rules.each do |rule|
puts rule[:title]Timer.start!(rule[:minutes]) do |minutes_left|
timer_report minutes_left
end
end
end
enddef rules
[{ title: "Let's work", minutes: 25 },
{ title: "Let's rest", minutes: 5 }] * 4 +
[{ title: "Let's walk for 15 minutes", minutes: 15 }]
enddef say(text)
puts text
Talks.say text
enddef timer_report(minutes_left)
say minutes_leftFile.open(File.expand_path('~/.pomo_stat'), 'w') do |f|
f.write("#{minutes_left} minutes left")
end
end
}
```### Done.
Now you have to go and do some awesome work using brand new tool.
## License
Anything you want. But I'm not responsible.