Skip to content

Instantly share code, notes, and snippets.

@vedant1811
vedant1811 / settings.py
Last active February 26, 2024 11:47
Disable celery in django test.
# ...
# Set the class as TEST_RUNNER in settings.py
TEST_RUNNER = 'app.test.TestRunner'
@vedant1811
vedant1811 / 1.js
Last active November 28, 2019 07:46
// Paste this in linkedin my connections to toggle all "remove connection" menu and auto accept the confirmation dialog
Array.from(document.querySelectorAll(".mn-connection-card__dropdown-trigger")).forEach(button=>button.click())
window.setInterval(function(){
document.querySelectorAll('[data-control-name="confirm_removed"]')[0].click()
}, 100);
@vedant1811
vedant1811 / lines of code
Created September 18, 2019 19:51
Useful commands
git ls-files | xargs wc -l
@vedant1811
vedant1811 / flatten.rb
Last active June 2, 2019 04:02
Flatten Array
def flatten_array(array)
ans = []
array&.each do |element|
if element.is_a? Array
ans += flatten_array(element)
else
ans << element
end
end
ans
# https://stackoverflow.com/a/22933955
git config --global push.default current
https://stackoverflow.com/a/22147540
git config --global branch.autosetuprebase always
git config --global branch.autosetupmerge always
@vedant1811
vedant1811 / regexes.rb
Last active January 9, 2019 06:02
Common useful regexes
# https://rubular.com/r/RQobzZSU9KPSYI
usernames = /^[a-zA-Z]+[a-zA-Z0-9_.-]*$/
def flatten_array(array)
result = []
array.each do |e|
if e.is_a? Array
result += flatten_array e
else
result << e
end
end
result
@vedant1811
vedant1811 / database.yml
Last active September 4, 2018 19:54
Setup postgres for rails dev (mac & ubuntu)
default: &default
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
host: localhost
username: rails
password: rails
development:
def catch(arr, k)
ps = 0
ts = 0
count = 0
arr.each do |e|
if e == 'T'
if ps > 0
ps -= 1
count += 1
def balance(string)
offset = 0
swaps = 0
string.each_char do |c|
if c == '['
if offset > 0
swaps += offset
end
offset -= 1
else