Skip to content

Instantly share code, notes, and snippets.

@PomepuyN
PomepuyN / Watch face Ambient mode detection
Last active November 5, 2018 23:07
Allow to detect Ambient mode to switch Watch face display on Wear devices
Handler handler = new Handler(Looper.getMainLooper());
final DisplayManager displayManager = (DisplayManager) getSystemService(Context.DISPLAY_SERVICE);
displayManager.registerDisplayListener(new DisplayManager.DisplayListener() {
@Override
public void onDisplayAdded(int displayId) {
}
@Override
@devunwired
devunwired / ExampleFragment.java
Created May 15, 2014 17:03
Method for animating Android fragment positions during a add/replace/remove transition using custom properties. This method does not require subclassing target views with additional setter methods, but instead requires subclassing the fragment...something you are likely already doing.
/**
* An example of adding these transitions to a Fragment. This simple
* version just applies opposite transitions to any Fragment whether it is
* entering or exiting view. You can also inspect the transit mode parameter
* (i.e. TRANSIT_FRAGMENT_OPEN, TRANSIT_FRAGMENT_CLOSE) in combination to do
* different animations for, say, adding a fragment versus popping the back stack.
*
* Transactions without an explicit transit mode set, in this example, will not
* animate. Allowing the initial fragment add, for example, to simply appear.
*/
@vmrob
vmrob / count_objects.py
Created April 15, 2014 22:19
count objects script for space engineers game
# The MIT License (MIT)
#
# Copyright (c) 2014 Victor Robertson
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
@pablomoretti
pablomoretti / gist:9748230
Created March 24, 2014 20:17
SimpleDateFormatThreadSafe
package com.foocoders.text;
import java.text.AttributedCharacterIterator;
import java.text.DateFormatSymbols;
import java.text.FieldPosition;
import java.text.NumberFormat;
import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Calendar;
@Takhion
Takhion / ArcUtils.java
Last active April 11, 2022 02:29
Collection of methods to achieve better circular arc drawing, as Canvas.drawArc() is unreliable. See the related article: https://medium.com/p/9155f49166b8
/**
* ArcUtils.java
*
* Copyright (c) 2014 BioWink GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
@lelandbatey
lelandbatey / whiteboardCleaner.md
Last active April 25, 2024 02:01
Whiteboard Picture Cleaner - Shell one-liner/script to clean up and beautify photos of whiteboards!

Description

This simple script will take a picture of a whiteboard and use parts of the ImageMagick library with sane defaults to clean it up tremendously.

The script is here:

#!/bin/bash
convert "$1" -morphology Convolve DoG:15,100,0 -negate -normalize -blur 0x1 -channel RBG -level 60%,91%,0.1 "$2"

Results

@itsalif
itsalif / SimpleXmlRequest.java
Last active February 25, 2019 16:03 — forked from ficusk/GsonRequest.java
Volley adapter for making XML Requests. It uses Simple-XML for serializing XML to Objects (http://simple.sourceforge.net/). Code is based of GsonRequest. Hope someone finds it useful.
import java.io.UnsupportedEncodingException;
import java.util.Map;
import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister;
import com.android.volley.AuthFailureError;
import com.android.volley.NetworkResponse;
import com.android.volley.ParseError;
import com.android.volley.Request;
@christianroman
christianroman / training.sh
Last active October 26, 2021 06:04
Tesseract OCR training new font
#! /bin/bash
# build the environment
mkdir tessenv; cd tessenv
TROOT=`pwd`
mkdir $TROOT/stockfonts; mkdir $TROOT/build; mkdir $TROOT/build/eng
echo "Environment built"
# Get the stock english fonts from Google (old, but they work)
cd $TROOT/stockfonts
GET http://tesseract-ocr.googlecode.com/files/boxtiff-2.01.eng.tar.gz > boxtiff-2.01.eng.tar.gz
@colemanfoley
colemanfoley / gist:3747574
Created September 19, 2012 03:48
Pig Latin translator
#The main method, it takes a string that is an English word and returns that word in Pig Latin.
#All words have "ay" appended to them in the line just before the return statement. If the word
#begins with a vowel, it is sent to the << "ay" line unmodified.
#If it is exactly three letters long, the second two characters of english_word are made the first
#two of pig_latin_word, then the first letter of english_word is made the third character of
#pig_latin_word. Then the word is ready to get the << "ay" treatment.
def translate(english_word)
if is_vowel?(english_word[0])
pig_latin_word = english_word
@chrisjenx
chrisjenx / gist:3405429
Created August 20, 2012 16:14
BasePagerFragment - Simple way to place a FragmentViewPager in a Fragment!
/**
* @project
* @author chris.jenkins
* @created Dec 28, 2011
*/
package com.application.android.ui.fragments;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.FragmentStatePagerAdapter;