Skip to content

Instantly share code, notes, and snippets.

@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 / FinderDrawView.java
Created October 14, 2015 09:10
Draws lines on the set drawable based on the user touches. sample: http://imgur.com/RNO6MA0
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.ViewTreeObserver;
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 / lua_functions.c
Created July 25, 2015 14:25
lua_functions accepted by telegram-cli
struct lua_function functions[] = {
{"get_contact_list", lq_contact_list, { lfp_none }},
{"get_dialog_list", lq_dialog_list, { lfp_none }},
{"rename_chat", lq_rename_chat, { lfp_chat, lfp_string, lfp_none }},
{"send_msg", lq_msg, { lfp_peer, lfp_string, lfp_none }},
{"send_typing", lq_send_typing, { lfp_peer, lfp_none }},
{"send_typing_abort", lq_send_typing_abort, { lfp_peer, lfp_none }},
{"send_photo", lq_send_photo, { lfp_peer, lfp_string, lfp_none }},
{"send_video", lq_send_video, { lfp_peer, lfp_string, lfp_none }},
{"send_audio", lq_send_audio, { lfp_peer, lfp_string, lfp_none }},
@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 / model_method.rb
Last active August 29, 2015 14:17
find_or_create_by with the option to pass (..., case_sensitive: false)
# from http://stackoverflow.com/a/2439293/1396264
def self.find_or_create_by_name(*args)
puts args.inspect
options = args.extract_options!
options[:name] = args[0] if args[0].is_a?(String)
case_sensitive = options.delete(:case_sensitive)
conditions = case_sensitive ? ['name = ?', options[:name]] :
['UPPER(name) = ?', options[:name].upcase]
where(conditions).first || create(options)
end
@vedant1811
vedant1811 / POJOToJSON.java
Created February 19, 2015 15:56
POJOToJSON
package vedant.olahackathon;
import android.util.Log;
import org.codehaus.jackson.JsonFactory;
import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.map.DeserializationConfig;
import org.codehaus.jackson.map.ObjectMapper;
import java.io.FileWriter;
@vedant1811
vedant1811 / JsonArrayRequest.java
Created February 16, 2015 14:25
JsonArrayRequest based on volley
import com.android.volley.NetworkResponse;
import com.android.volley.ParseError;
import com.android.volley.Response;
import com.android.volley.toolbox.HttpHeaderParser;
import com.android.volley.toolbox.JsonRequest;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@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.