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 / KotlinExtensions.kt
Created June 6, 2018 07:15
Useful android kotlin extensions
/**
* Use as `"#fff".parseColor()`
*/
fun String.parseColor() = Color.parseColor(this)
/**
* Use as `16.spToPx(context)` or `16.5.spToPx(context)`
*/
fun Number.spToPx(context: Context) = TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_SP, this.toFloat(), context.resources.displayMetrics).toInt()
@vedant1811
vedant1811 / Spinner.java
Created January 6, 2015 19:16
Custom Spinner to differentiate between user selected and prorammatically selected item. Make sure to call correct method to use this feature
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.AdapterView;
/**
* Used this to differentiate between user selected and prorammatically selected
* Call {@link Spinner#programmaticallySetPosition} to use this feature.
* Created by vedant on 6/1/15.
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.text.SpannableStringBuilder;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.TextView;
@vedant1811
vedant1811 / info.txt
Last active May 11, 2020 01:10
Saves all chat history of a telegram user. use as `telegram-cli -D -s save_chat_history.lua`
I had to change this in the telegram CLI to make it work:
https://github.com/vedant1811/tg/commit/e068c2549f2f155ba9c40bd7cee8b076d03b417f
@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_.-]*$/