Skip to content

Instantly share code, notes, and snippets.

View DawnImpulse's full-sized avatar

Saksham Khurana DawnImpulse

View GitHub Profile
@DawnImpulse
DawnImpulse / middleware-test.js
Created February 12, 2018 04:14 — forked from CodeVachon/middleware-test.js
express middleware mocha test
var middleware = require('middleware'), // the Middleware you want to test
httpMocks = require('node-mocks-http'), // quickly sets up REQUEST and RESPONSE to be passed into Express Middleware
request = {}, // define REQUEST
response = {} // define RESPONSE
;
describe('Middleware test', function(){
context('Valid arguments are passed', function() {
beforeEach(function(done) {
/*
@DawnImpulse
DawnImpulse / OkHttpProgressGlideModule.java
Created May 25, 2018 02:20 — forked from TWiStErRob/OkHttpProgressGlideModule.java
Full POC for showing progress of loading in Glide v3 via OkHttp v2
// TODO add <meta-data android:value="GlideModule" android:name="....OkHttpProgressGlideModule" />
// TODO add <meta-data android:value="GlideModule" tools:node="remove" android:name="com.bumptech.glide.integration.okhttp.OkHttpGlideModule" />
// or not use 'okhttp@aar' in Gradle depdendencies
public class OkHttpProgressGlideModule implements GlideModule {
@Override public void applyOptions(Context context, GlideBuilder builder) { }
@Override public void registerComponents(Context context, Glide glide) {
OkHttpClient client = new OkHttpClient();
client.networkInterceptors().add(createInterceptor(new DispatchingProgressListener()));
glide.register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(client));
}
@DawnImpulse
DawnImpulse / LetterSpacingTextView.java
Created May 27, 2018 06:56 — forked from SyllaJay/LetterSpacingTextView.java
Android TextView, that allows changing the letter spacing of the text. @author: Pedro Barros
/**
* Text view that allows changing the letter spacing of the text.
*
* @author Pedro Barros (pedrobarros.dev at gmail.com)
* @since May 7, 2013
*/
public static class LetterSpacingTextView extends TextView {
private float spacing = Spacing.NORMAL;
private CharSequence originalText = "";
@DawnImpulse
DawnImpulse / Uuid
Created June 18, 2018 09:40
Javascript generating GUID / UUID
function createUUID() {
// http://www.ietf.org/rfc/rfc4122.txt
var s = [];
var hexDigits = "0123456789abcdef";
for (var i = 0; i < 36; i++) {
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
}
s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
s[8] = s[13] = s[18] = s[23] = "-";
@DawnImpulse
DawnImpulse / Needle POST
Created May 29, 2018 07:53
Needle (request) post method basic implementation (https://www.npmjs.com/package/needle)
var options = {
headers: {
'Content-Type': 'application/json'
}
};
needle('post',url, body,options)
.then((response) => {
if (response.statusCode !== 200) {
//do things
/**
* Layout for ingredients in recipe info
*/
fun ingredientLayout(ingredientsList: List<RecipeIngredientsPojo>) {
var i = 1
mutableListIngredients.clear()
ingredientLayout.removeAllViews()
if (!ingredientsList.isEmpty()) {
AlertDialog dialog = null;
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
final EditText editText;
dialogBuilder.setTitle("Edit Balance ");
LayoutInflater inflater = getLayoutInflater();
View dialogView = inflater.inflate(R.layout., null);
dialogBuilder.setView(dialogView);
editText = (EditText) dialogView.findViewById(R.id.alert_edit_text);
@DawnImpulse
DawnImpulse / Suffix for numeral (android)
Created June 25, 2018 12:22
Use to add suffix like 2k & 8M to numbers
fun withSuffix(count: Int): String {
if (count < 1000) return "" + count
val exp = (Math.log(count.toDouble()) / Math.log(1000.0)).toInt()
return String.format("%.1f %c",
count / Math.pow(1000.0, exp.toDouble()),
"kMGTPE"[exp - 1])
}
@DawnImpulse
DawnImpulse / color.java
Created September 8, 2018 14:40
Add color in java string (android)
String text = "This text is white. <font color=\"blue\">This text is blue.</font>";
textView.setText(Html.fromHtml(text), BufferType.SPANNABLE);
// -----
SpannableStringBuilder builder = new SpannableStringBuilder();
String red = "this is red";
SpannableString redSpannable= new SpannableString(red);
redSpannable.setSpan(new ForegroundColorSpan(Color.RED), 0, red.length(), 0);
@DawnImpulse
DawnImpulse / caps.kt
Created September 8, 2018 14:54
first letter capital
fun capWord(string: String): String {
val result = StringBuilder(string.length)
val words = string.split("\\ ".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
for (i in words.indices) {
result.append(Character.toUpperCase(words[i][0])).append(words[i].substring(1)).append(" ")
}
return result.toString()
}