Skip to content

Instantly share code, notes, and snippets.

class GardenHose:
def countDead(self, n, rowDist, colDist, hoseDist):
count = 0
for row in range(0, n):
for col in range(0, n):
if (row + 1) * rowDist <= hoseDist or (n - row) * rowDist <= hoseDist:
continue
if (col + 1) * colDist <= hoseDist or (n - col) * colDist <= hoseDist:
continue
count += 1
@sunloverz
sunloverz / gist:99db6a4d36da96488b50
Created December 24, 2014 05:57
GOROOT environment variable is empty or could not be detected properly.
I just found another way to add GOPATH sources in the project.
1) Open Project Structure.
2) Select Project Settings -> Modules -> {your module}
3) Under sources label, select Add Content Root to add GOPATH folder.
4) Mark src folder in GOPATH folder as Sources.
Then the GOPATH is added to the project, and everything works fine. The plugin do not need to know anything about GOPATH.
I think it should works for non-IDEA IDEs.
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
Hmm…it looks like I just wrote War and Peace
@sunloverz
sunloverz / postgres-9.3
Created June 1, 2015 09:49
Create user and database in postgresql
sudo -u postgres psql
postgres=# create user "guy_on_stackoverflow" with password 'keepitonthedl';
postgres=# create database "dcaclab_development" owner "guy_on_stackoverflow";
str = '123456789012345678909999991234569999'
h = {}
str.split("").each do |i|
h[i] = 0 if h[i].nil?
h[i] += 1
end
h.each do |key, value|
puts "#{key} #{"*"*value}"
tyler@tyler-durden:~/EDGEAuditor-master$ rake db:migrate
/home/tyler/.rvm/gems/ruby-2.3.0@rails4/gems/activesupport-4.0.0/lib/active_support/values/time_zone.rb:282: warning: circular argument reference - now
/home/tyler/.rvm/gems/ruby-2.3.0@rails4/gems/logglier-0.2.13/lib/logglier/client/http/sync.rb:11: warning: constant Logglier::Client::HTTP::NetHTTPProxy::TimeoutError is deprecated
rake aborted!
Rails::Application::RoutesReloader#execute_if_updated delegated to updater.execute_if_updated, but updater is nil: #<Rails::Application::RoutesReloader:0x005645877ac998 @paths=["/home/tyler/EDGEAuditor-master/config/routes.rb", "/home/tyler/.rvm/gems/ruby-2.3.0@rails4/gems/ckeditor-4.2.3/config/routes.rb"], @route_sets=[#<ActionDispatch::Routing::RouteSet:0x00564589aa08c8>, #<ActionDispatch::Routing::RouteSet:0x0056458cac2f60>, #<ActionDispatch::Routing::RouteSet:0x005645877a7538>]>
/home/tyler/.rvm/gems/ruby-2.3.0@rails4/gems/railties-4.0.0/lib/rails/application/routes_reloader.rb:10:in `rescue in execute_if_upd
Database tables:
Users {
id
name
}
Roles {
id
name
@sunloverz
sunloverz / gist:c31e54591c80d9dd24bdf013e2892cf6
Created April 30, 2019 13:58
Ruby open class refactoring
class ActiveRecord::Base
def self.has_statuses(*status_names)
validates :status,
:presence => true,
:inclusion => { :in => status_names }
# Status Finders
status_names.each do |status_name|
scope "all_#{status_name}", where(:status => status_name)
end

Keybase proof

I hereby claim:

  • I am sunloverz on github.
  • I am aomurbekov (https://keybase.io/aomurbekov) on keybase.
  • I have a public key ASCQz5MXYn-i5vkLEI3JBFbskvAZ3UlUmp0kjJVGAxL4Rwo

To claim this, I am signing this object: