Skip to content

Instantly share code, notes, and snippets.

@charlieanna
charlieanna / db.rake
Created February 20, 2023 10:35 — forked from hopsoft/db.rake
Rails rake tasks for dump & restore of PostgreSQL databases
# lib/tasks/db.rake
namespace :db do
desc "Dumps the database to db/APP_NAME.dump"
task :dump => :environment do
cmd = nil
with_config do |app, host, db, user|
cmd = "pg_dump --host #{host} --username #{user} --verbose --clean --no-owner --no-acl --format=c #{db} > #{Rails.root}/db/#{app}.dump"
end
puts cmd
class Solution:
def generateParenthesis(self, n: int) -> List[str]:
result = []
def helper(l, r, temp):
if l == r == n:
result.append("".join(temp[:]))
if l < n:
helper(l + 1, r, temp + ["("])
if r < l:
helper(l, r + 1, temp + [")"])
class Solution:
def subsetsWithDup(self, nums: List[int]) -> List[List[int]]:
result = []
nums.sort()
def helper(idx, temp):
result.append(temp[:])
for i in range(idx, len(nums)):
if i > idx and nums[i] == nums[i-1]:
continue
temp.append(nums[i])
class Solution:
def subsets(self, nums: List[int]) -> List[List[int]]:
result = []
temp = []
def helper(idx):
if idx > len(nums):
return
result.append(temp[:])
for i in range(idx, len(nums)):
class Solution:
def combinationSum3(self, k: int, n: int) -> List[List[int]]:
result = []
def helper(idx):
if len(temp) == k and sum(temp) == n:
result.append(temp[:])
if sum(temp) > n or len(temp) > k:
return
for i in range(idx, 10):
class Solution:
def combinationSum2(self, nums: List[int], target: int) -> List[List[int]]:
nums.sort()
result = []
def helper(idx, temp, cur):
if cur == target :
result.append(temp[:])
if cur > target:
return
for i in range(idx, len(nums)):
class Solution:
def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]:
result = []
def helper(idx, temp, cur):
if cur == target:
result.append(temp[:])
return
if cur > target:
return
@charlieanna
charlieanna / comb.py
Created March 19, 2020 08:27
77. Combinations
# temp + [i] creates a new array pointer that is why we do a copy. deep copy creates new instance of element inside the array. here copy is enough.
class Solution:
def combine(self, n: int, k: int) -> List[List[int]]:
def dfs(idx, temp):
if len(temp) == k:
result.append(temp[:])
# return
for i in range(idx, n + 1):
temp.append(i)
int icon = 0;// = R.drawable.ic_stat_gcm;
long when = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.icon, "You have a new "+app, when);
notification.vibrate = new long[] { 100, 250, 100, 500};
String title = context.getString(R.string.app_name);
Intent notificationIntent = null;
// notificationIntent = new Intent(context, HomeScreen.class) ;
@charlieanna
charlieanna / 0_reuse_code.js
Created March 29, 2014 04:53
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console