Skip to content

Instantly share code, notes, and snippets.

View cachapa's full-sized avatar

Daniel Cachapa cachapa

View GitHub Profile
import 'package:firedart/firedart.dart';
import 'package:hive/hive.dart';
/// Stores tokens using a Hive store.
/// Depends on the Hive plugin: https://pub.dev/packages/hive
class HiveStore extends TokenStore {
static const keyToken = "auth_token";
static Future<HiveStore> create() async {
// Make sure you call both:
@cachapa
cachapa / preferences_store.dart
Last active July 30, 2023 11:56
A firedart TokenStore that uses Android and iOS preferences as persistence mechanism
import 'dart:convert';
import 'package:firedart/firedart.dart';
import 'package:shared_preferences/shared_preferences.dart';
/// Stores tokens as preferences in Android and iOS.
/// Depends on the shared_preferences plugin: https://pub.dev/packages/shared_preferences
class PreferencesStore extends TokenStore {
static const keyToken = "auth_token";
@cachapa
cachapa / gif_creator.sh
Last active April 1, 2022 12:07
Shell script to generate high-quality animated gifs from a video file
#!/bin/bash
# Based on http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html
# Requires ffmpeg
filename="${1%.*}"
palette="/tmp/palette.png"
filters="scale=320:-1:flags=lanczos"
ffmpeg -v warning -i "$1" -vf "$filters,palettegen" -y $palette
ffmpeg -v warning -i "$1" -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse" -y "$filename.gif"
@cachapa
cachapa / LogView.java
Last active December 2, 2020 10:54
An Android view for showing logs in realtime - useful for debugging
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.widget.ScrollView;
import android.widget.TextView;
import java.util.Locale;
public class LogView extends ScrollView {
@cachapa
cachapa / DownloadManager.java
Created November 21, 2015 15:11
General-purpose Android file downloads with threading and queuing. The only dependency is OkHttp.
package com.codingbuffalo.aerialdream.util;
import android.os.Handler;
import android.support.annotation.UiThread;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;
import java.io.File;