Skip to content

Instantly share code, notes, and snippets.

/**
* Implementation of [SSLSocketFactory] that adds [TlsVersion.TLS_1_2] as an enabled protocol for every [SSLSocket]
* created by [delegate].
*
* [See this discussion for more details.](https://github.com/square/okhttp/issues/2372#issuecomment-244807676)
*
* @see SSLSocket
* @see SSLSocketFactory
*/
class Tls12SocketFactory(private val delegate: SSLSocketFactory) : SSLSocketFactory() {
@Suppress("UNCHECKED_CAST")
@Singleton
class ViewModelFactory @Inject constructor(
private val creators: Map<Class<out ViewModel>, @JvmSuppressWildcards Provider<ViewModel>>
) : ViewModelProvider.Factory {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
val creator = creators[modelClass] ?: creators.entries.firstOrNull {
modelClass.isAssignableFrom(it.key)
}?.value ?: throw IllegalArgumentException("unknown model class $modelClass")
try {
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER)
@MapKey
annotation class ViewModelKey(val value: KClass<out ViewModel>)
@zmwas
zmwas / authInterceptor.java
Created January 6, 2020 11:35
auth interceptor
private Interceptor getAuthInterceptor(SessionManager sessionManager) {
Interceptor authInterceptor = chain -> {
String authToken = "";
SessionManager.UserDetail userDetail = sessionManager.getUserDetails();
if (userDetail != null) {
authToken = userDetail.authToken;
// if(authToken != null) {System.out.println(authToken);}
}
Request request = chain.request();
function LinearSearch(list, value){
//loop through the list until you find the value
for(let i = 0; i < list.length; i++){
if(list[i] === value) return i;
}
return -1;
}
const list = [1,2,3,4,5];
console.log(LinearSearch(list, 3)); // 2
/**
* @return {number}
*/
function BinarySearch (list, value) {
let start = 0
let end = list.length - 1
let middle = Math.floor((start + end) / 2)
//check that the value we are searching for is not equal to the middle
@zmwas
zmwas / enzyme_render_diffs.md
Created July 19, 2018 08:58 — forked from fokusferit/enzyme_render_diffs.md
Difference between Shallow, Mount and render of Enzyme

Shallow

Real unit test (isolation, no children render)

Simple shallow

Calls:

  • constructor
  • render
@zmwas
zmwas / README.md
Created June 12, 2018 07:11 — forked from joyrexus/README.md
Vanilla JS equivalents of jQuery methods

Sans jQuery

Events

// jQuery
$(document).ready(function() {
  // code
})
@zmwas
zmwas / ballot.sol
Created May 16, 2018 13:17
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.4.23+commit.124ca40d.js&optimize=false&gist=
pragma solidity ^0.4.0;
contract Ballot {
struct Voter {
uint weight;
bool voted;
uint8 vote;
address delegate;
}
struct Proposal {
@zmwas
zmwas / gist:8f52dabcd2ec4e9a60cfe552c6ff4558
Created July 12, 2017 07:42 — forked from skyuplam/gist:ffb1b5f12d7ad787f6e4
Flask-Security and Flask-Admin example by Steve Saporata
# Example of combining Flask-Security and Flask-Admin.
# by Steve Saporta
# April 15, 2014
#
# Uses Flask-Security to control access to the application, with "admin" and "end-user" roles.
# Uses Flask-Admin to provide an admin UI for the lists of users and roles.
# SQLAlchemy ORM, Flask-Mail and WTForms are used in supporting roles, as well.
from flask import Flask, render_template
from flask.ext.sqlalchemy import SQLAlchemy