Skip to content

Instantly share code, notes, and snippets.

Avatar

Volodymyr Shatskyi vlad-shatskyi

View GitHub Profile
View teste.rb
user = User.find(1)
site = Site.new
site.url = "http://www.google.com"
site.name = "Google"
user.sites << site
if user.save
'cool'
View gist:5041680
names = File.read('names.txt').split(',').map { |str| str[1..-2] }
letters = ('A'..'Z').to_a.join
sum = 0
names.each_with_index do |name, i|
score = 0
name.each_char do |char|
score += (letters.index(char) + 1) * (i + 1)
end
sum += score
@vlad-shatskyi
vlad-shatskyi / notifyosd.zsh
Last active Dec 15, 2015 — forked from ihashacks/notifyosd.zsh
Displays a notification when a command, that takes over 10 seconds to execute, finishes and only if the current window isn't the terminal. Add to your .zshrc: [ -e path/to/notifyosd.zsh ] && . path/to/notifyosd.zsh
View notifyosd.zsh
function active-window-id {
echo `xprop -root | awk '/_NET_ACTIVE_WINDOW\(WINDOW\)/{print $NF}'`
}
# end and compare timer, notify-send if needed
function notifyosd-precmd() {
if [ ! -z "$cmd" ]; then
cmd_end=`date +%s`
((cmd_time=$cmd_end - $cmd_start))
fi
View test.rb
require 'mechanize'
require 'json'
agent = Mechanize.new
headers = {
'X-Requested-With' => 'XMLHttpRequest',
'Content-Type' => 'application/x-www-form-urlencoded',
'Accept' => '*/*',
'Cookie' => 'removed'
}
@vlad-shatskyi
vlad-shatskyi / gems.rb
Last active Dec 15, 2015
Installs all the required gems in the specified file or directory.
View gems.rb
#!/usr/bin/env ruby
def installed?(gem_name)
require gem_name
true
rescue LoadError
false
end
def required_gems(file_name)
View gist:0c2f7e825bb71e4274d2
calculatePadding :: Int -> Int
calculatePadding = ceiling . log . fromIntegral
Defaulting the following constraint(s) to type Double
(RealFrac b0)
arising from a use of ceiling at src/Cat/Decorators.hs:21:22-28
(Num b0)
arising from a use of fromIntegral
at src/Cat/Decorators.hs:21:38-49
View ask
module Main where
import System.Environment
import System.IO (hFlush, stdout)
ask :: (Show a, Read b) => a -> IO b
ask question = do
putStr $ show question
hFlush stdout
answer <- getLine