Skip to content

Instantly share code, notes, and snippets.

@tokudu
tokudu / StrictModeManager.kt
Last active April 5, 2021 21:04
StrictMode util that allows you to whitelist stack traces
package com.myapp
import android.os.Build
import android.os.StrictMode
import com.snap.core.BuildConfig
import com.snapchat.android.framework.logging.Timber
import java.lang.reflect.Field
import java.lang.reflect.Modifier
/**
2018-07-03 11:03:13.648 22151-22151/com.myapp D/StrictMode: StrictMode policy violation; ~duration=9 ms: android.os.StrictMode$StrictModeDiskReadViolation: policy=3211271 violation=2
at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1293)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:183)
at libcore.io.IoUtils.canOpenReadOnly(IoUtils.java:163)
at dalvik.system.DexPathList$Element.findNativeLibrary(DexPathList.java:550)
at dalvik.system.DexPathList.findLibrary(DexPathList.java:480)
at dalvik.system.BaseDexClassLoader.findLibrary(BaseDexClassLoader.java:84)
at java.lang.Runtime.loadLibrary0(Runtime.java:966)
at java.lang.System.loadLibrary(System.java:1567)
at com.qualcomm.qti.Performance.<clinit>(Performance.java:21)
@tokudu
tokudu / SSNFormattingTextWatcher.java
Created October 12, 2016 04:52
TextWatcher for formatting SSN as XXX-XX-XXXX
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;
public class SSNFormattingTextWatcher implements TextWatcher {
private EditText mEditText;
private boolean mShouldDeleteSpace;
public SSNFormattingTextWatcher(EditText editText) {
mEditText = editText;
// If true, the emails will be sent to the support email
var DEV_MODE = false;
// Index of some column that is not used.
var SENT_COLUMN = 15;
// Place your Grid API Key here.
var SENDGRID_KEY = PUT_YOUR_SEND_GRID_API_KEY_HERE;
// The emails will be send here.
var EMAIL_TO = "[email protected]";
// Errors will be send here
@tokudu
tokudu / restore_db.sh
Created June 25, 2015 05:16
Simple shell script to restore a mongodb databse from an S3 backup using mongorestore
#!/bin/bash
TIMESTAMP=`date +%F-%H%M`
DUMP_LOCAL=/tmp/dump-${TIMESTAMP}
# exit if something fails
set -e
if [ $# -lt 2 ]
then
@tokudu
tokudu / backup_db.sh
Created June 25, 2015 05:15
Simple shell script to back up a mongodb database to S3 using mongodump.
#!/bin/bash
MONGODUMP_PATH="/usr/bin/mongodump"
TIMESTAMP=`date +%F-%H%M`
S3_CONFIG="/home/ubuntu/.s3cfg"
CHUNK_SIZE="500m" # 500 mg
DUMPS_TO_KEEP=30
if [ $# -lt 2 ]
int padding = 10; // in pixels
yourTextView.setShadowLayer(padding /* radius */, 0, 0, 0 /* transparent */);
yourTextView.setPadding(padding, padding, padding, padding);
// Now create the new span
String str = "Some really long string goes in here";
Spannable spannable = new SpannableString(str);
spannable.setSpan(new PaddingBackgroundColorSpan(
getResources().getColor(android.R.color.black),
padding
@tokudu
tokudu / PaddingBackgroundColorSpan.java
Created February 2, 2015 23:22
How to create BackgroundColorSpan with padding
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.text.style.LineBackgroundSpan;
public class PaddingBackgroundColorSpan implements LineBackgroundSpan {
private int mBackgroundColor;
private int mPadding;
private Rect mBgRect;
@tokudu
tokudu / background_color_span.java
Last active November 21, 2016 11:35
BackgroundColorSpan Example
String str = "Some really long string goes in here";
Spannable spannable = new SpannableString(str);
spannable.setSpan(new BackgroundColorSpan(
getResources().getColor(android.R.color.black)
), 0, str.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
yourTextView.setText(spannable);
@tokudu
tokudu / embed.html
Last active October 13, 2015 07:07
Embeddable Umane player
<script>(function(d, s, id) {
var js, ujs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//umano.me/widgets/player.min.js";
ujs.parentNode.insertBefore(js, ujs);
}(document, 'script', 'umano-jssdk'));</script>
<div class="umano-player" data-canonical="http://pandodaily.com/2012/11/21/umano-wants-to-tell-you-the-news-literally">
</div>