Skip to content

Instantly share code, notes, and snippets.

import { Location } from 'history';
import { useEffect, useState } from 'react';
import { useHistory } from 'react-router';
const useBrowserBackStack = () => {
const history = useHistory();
const [backStack, setBackStack] = useState<Location[]>([]);
useEffect(() => {
history.listen((location, action) => {
setBackStack(backStack => {
@mrhether
mrhether / NothingSelectedSpinnerAdapter.java
Created January 2, 2019 18:38
NothingSelectedSpinnerAdapter
package com.surpriise.vouchrcommon.ui.components;
import android.content.Context;
import android.database.DataSetObserver;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.SpinnerAdapter;
private class GameInterface {
public void restartGame() {
this.webView.evaluateJavascript("restartGame()", null);
}
public void startGame() {
this.webView.evaluateJavascript("startGame()", null);
}
@mrhether
mrhether / OkClientBuilder.java
Last active December 23, 2022 17:21
XHttpMethodOverride Interceptor for OkHttp and Retrofit.
public OkHttpClient getOkClient() {
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.addInterceptor(new XHttpMethodOverrideInterceptor());
return builder.build()
}
@mrhether
mrhether / TwitterAuth.m
Created May 3, 2017 15:53
Twitter Auth Example
#import <AFNetworking/AFNetworking.h>
- (void) requestToken {
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc] initWithSessionConfiguration:configuration];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
NSData *plainData = [[NSString stringWithFormat:@"%@:%@", @"YOUR_TOKEN", @"YOUR_SECRET"] dataUsingEncoding:NSUTF8StringEncoding];
NSString *encodedUsernameAndPassword = [plainData base64EncodedStringWithOptions:0];
TwitterServiceBuilder.getTwitterService().search("test").enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
Toast.makeText(TwitterActivity.this, response.toString(), Toast.LENGTH_LONG).show();
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
Toast.makeText(TwitterActivity.this, t.toString(), Toast.LENGTH_LONG).show();
}
@mrhether
mrhether / moveRes.py
Last active January 10, 2017 15:58
Allows you to move resources from one android app/lib to another
import os, sys
if len(sys.argv) < 4:
print "Family you need 3 params, originalFolder, newResFolder, fileName"
else:
orginalResFolder = sys.argv[1]
newResFolder = sys.argv[2]
fileNames = sys.argv[3:]
print "files to move " + str(fileNames)
@mrhether
mrhether / OnSingleClickListener.java
Created May 9, 2016 19:46
OnSingleClickListener
/**
* Implementation of {@link OnClickListener} that ignores subsequent clicks that happen too quickly after the first one.<br/>
* To use this class, implement {@link #onSingleClick(View)} instead of {@link OnClickListener#onClick(View)}.
*/
public abstract class OnSingleClickListener implements OnClickListener {
private static final String TAG = OnSingleClickListener.class.getSimpleName();
private static final long MIN_DELAY_MS = 500;
private long mLastClickTime;
@mrhether
mrhether / WindowUtils.java
Created April 6, 2016 18:12
Window Utils Android
public class WindowUtils {
public static int getActionBarHeight(Context context) {
final TypedArray styledAttributes = context.getTheme().obtainStyledAttributes(
new int[]{R.attr.actionBarSize});
int actionBarHeight = (int) styledAttributes.getDimension(0, 0);
styledAttributes.recycle();
return actionBarHeight;
}
@mrhether
mrhether / UILabel+HTML.m
Created February 24, 2016 19:38
UILabel + HTML
#import "UILabel+HTML.h"
@implementation UILabel (HTML)
- (void) setHtml: (NSString*) html
{
// Add font from label
NSString* finalHtml = [html stringByAppendingString:[NSString stringWithFormat:@"<style>body{font-family: '%@'; font-size:%fpx;}</style>",
self.font.fontName,
self.font.pointSize]];