Skip to content

Instantly share code, notes, and snippets.

@sunloverz
sunloverz / gist:70575d09e67638c9b55ea53005ceafeb
Created June 2, 2021 11:08 — forked from guisehn/gist:6648c8fdcd1102a22a22
Backup Heroku Postgres database and restore to local database

Grab new backup

Command: heroku pg:backups capture -a [app_name]

Download

Command: curl -o latest.dump `heroku pg:backups public-url -a [app_name]`

Restore backup dump into local db

def get_pairs(arr, sum)
len = arr.length
seen = Array.new(len, false)
result = []
for i in 0..len-1
for j in i+1..len-1
if arr[i] + arr[j] == sum && !seen[j] && !seen[i]
seen[i], seen[j] = true, true
result << [arr[i], arr[j]]
@sunloverz
sunloverz / sum_of_pairs.java
Last active February 10, 2021 05:54
Sum of pairs
package hash_table;
import java.util.ArrayList;
public class SumOfPairs {
public static void getPairs(int[] arr, int sum) {
int length = arr.length;
boolean[] seen = new boolean[length];
ArrayList<ArrayList<Integer>> list = new ArrayList<>();
ArrayList<Integer> temp;

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:

@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
Database tables:
Users {
id
name
}
Roles {
id
name
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
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}"
@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";
Hmm…it looks like I just wrote War and Peace