Skip to content

Instantly share code, notes, and snippets.

View jeffypooo's full-sized avatar
🔥

Jefferson Jones jeffypooo

🔥
View GitHub Profile
@jeffypooo
jeffypooo / ParseTestBase.java
Created November 6, 2015 19:48
Unit Test setup for code using Parse's Android SDK
@RunWith(RobolectricTestRunner.class)
@Config(manifest = TestConstants.MOBILE_ROBOLECTRIC_MANIFEST_PATH, sdk = 21)
public abstract class ParseTestBase {
static boolean parseInit = false;
@Before
public void setup() throws ParseException {
if (!parseInit) {
Context context = ShadowApplication.getInstance().getApplicationContext();
@jeffypooo
jeffypooo / ExceptionMatchers.java
Last active April 24, 2016 23:28
Some custom exception matchers for hamcrest
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
/**
* Hamcrest matchers for exceptions
*/
public class ExceptionMatchers {
@jeffypooo
jeffypooo / ViewMatchers.java
Created April 24, 2016 23:31
Hamcrest view matchers for Android + Robolectric
package com.beartooth.bronco;
import android.view.View;
import android.widget.TextView;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
/**
/**
* Workaround for https://code.google.com/p/android/issues/detail?id=197341
*/
private UUID byteSwappedUuid(UUID toSwap) {
ByteBuffer buffer = ByteBuffer.allocate(16);
buffer
.putLong(toSwap.getLeastSignificantBits())
.putLong(toSwap.getMostSignificantBits());
buffer.rewind();
buffer.order(ByteOrder.LITTLE_ENDIAN);
public class WorkerThread extends Thread {
private final LinkedBlockingQueue<Runnable> tasks;
private final AtomicBoolean cancelled;
private final AtomicBoolean safeCanceled;
public WorkerThread() {
this.tasks = new LinkedBlockingQueue<>();
this.cancelled = new AtomicBoolean(false);
this.safeCanceled = new AtomicBoolean(false);
@jeffypooo
jeffypooo / PCM_SineWave.java
Created January 24, 2017 23:38
Code to synthesize a 16 bit linear PCM sine wave (tone).
float freq = 440f;
float sRate = 8000f;
int numSamples = (int) (sRate * SINE_WAVE_DUR_SECS);
float[] rawSamples = new float[numSamples];
for (int i = 0; i < numSamples; ++i) {
rawSamples[i] = (float) Math.sin(2.0 * Math.PI * i / (sRate / freq));
}
sineWaveSamples = new byte[numSamples * 2];
int j = 0;
for (float sample : rawSamples) {
@jeffypooo
jeffypooo / UIViewController+Keyboard.swift
Created February 26, 2018 01:47
Keyboard handling extension for UIViewController
import UIKit
extension UIViewController {
func registerForKeyboardNotifications() {
let center = NotificationCenter.default
center.addObserver(
self,
selector: #selector(keyboardDidShow(_:)),
name: NSNotification.Name.UIKeyboardDidShow,
@jeffypooo
jeffypooo / AndroidVersionName.java
Created March 26, 2018 20:05
Android | Programmatically retrieve version name
try {
PackageInfo pInfo = this.getPackageManager().getPackageInfo(getPackageName(), 0);
String version = pInfo.versionName;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
@jeffypooo
jeffypooo / gist:84793e93f0b3c588861a24a2f6008a38
Last active April 18, 2018 22:11 — forked from dodyg/gist:5823184
Kotlin Programming Language Cheat Sheet Part 1

Intro

Kotlin is a new programming language for the JVM. It produces Java bytecode, supports Android and generates JavaScript. The latest version of the language is Kotlin M5.3

Kotlin project website is at kotlin.jetbrains.org.

All the codes here can be copied and run on Kotlin online editor.

Let's get started.

@jeffypooo
jeffypooo / Binary.swift
Created May 20, 2018 03:52
Generic serialization utility for Swift
//
// Binary.swift
//
// Created by Jefferson Jones on 2/14/17.
// Copyright © 2017 Jefferson Jones. All rights reserved.
//
import Foundation
class Binary {