Skip to content

Instantly share code, notes, and snippets.

@yeokm1
yeokm1 / archlinux-rpi3-serial-and-bluetooth.md
Last active October 9, 2021 09:59
Arch Linux Raspberry Pi 3 configuration to use both Serial Debug Port and Bluetooth

The new Raspberry Pi 3 released on 29 Feb 2016 has issues with its UART port as the pinout GPIO 14/15 on the pin header is now based on a low throughput mini-UART.

To understand the issue better than reading the wall of text below, you can see the talk I gave on this issue.

The actual hardware UART on the BCM2837 SoC has now been assigned to handle Bluetooth with the BCM43438 Wifi/Bluetooth chip. More details can be found here and here.

This mini-UART does not produce a stable baud rate as it fluctuates based on the Core clock speed whenever it rises or falls. The result is that the serial debug output is practically unusable. On Raspbian you may see garbage or nothing at all. The solution is simple, add core_freq=250 to /boot/config.txt to cap the core frequency to a constant value. This optio

@zhiguangwang
zhiguangwang / README.md
Last active April 29, 2024 12:56
Installing and running shadowsocks on Ubuntu Server

Installing and running shadowsocks on Ubuntu Server

16.10 yakkety and above

  1. Install the the shadowsocks-libev package from apt repository.

     sudo apt update
     sudo apt install shadowsocks-libev
    
  2. Save ss.json as /etc/shadowsocks-libev/config.json.

@DaveWoodCom
DaveWoodCom / String+Email.swift
Last active February 28, 2021 16:45
Swift method to check for a valid email address (uses Apples data detector instead of a regex)
extension String {
func isValidEmail() -> Bool {
guard !self.lowercaseString.hasPrefix("mailto:") else { return false }
guard let emailDetector = try? NSDataDetector(types: NSTextCheckingType.Link.rawValue) else { return false }
let matches = emailDetector.matchesInString(self, options: NSMatchingOptions.Anchored, range: NSRange(location: 0, length: self.characters.count))
guard matches.count == 1 else { return false }
return matches[0].URL?.scheme == "mailto"
}
}
@ph0b
ph0b / app_build.gradle
Last active November 20, 2019 09:21
config example on Multiple APK support and mixing gradle-stable and gradle-experimental plugin, for NDK-enabled Android projects. To support AS 2.0 debug, just add lib/build/intermediates/binaries/release/obj/[abi] to Symbol directories
apply plugin: 'com.android.application'
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
applicationId "com.example.yourapp"
minSdkVersion 16
targetSdkVersion 23
@TWiStErRob
TWiStErRob / OkHttpProgressGlideModule.java
Last active January 31, 2024 13:37
Full POC for showing progress of loading in Glide v3 via OkHttp v2
// TODO add <meta-data android:value="GlideModule" android:name="....OkHttpProgressGlideModule" />
// TODO add <meta-data android:value="GlideModule" tools:node="remove" android:name="com.bumptech.glide.integration.okhttp.OkHttpGlideModule" />
// or not use 'okhttp@aar' in Gradle depdendencies
public class OkHttpProgressGlideModule implements GlideModule {
@Override public void applyOptions(Context context, GlideBuilder builder) { }
@Override public void registerComponents(Context context, Glide glide) {
OkHttpClient client = new OkHttpClient();
client.networkInterceptors().add(createInterceptor(new DispatchingProgressListener()));
glide.register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(client));
}
@Plumillon
Plumillon / PFRecyclerViewAdapter.java
Last active April 1, 2022 07:29
Simpler generic RecyclerView.Adapter and RecyclerView.ViewHolder with click listener
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@AndroidT
AndroidT / GlideImageGetter
Last active December 30, 2020 12:55
GlideImageGetter uses Glide Image Library to load GIFs/JPG/PNG in HTML <img> tags into TextView
package com.example.name;
import android.content.Context;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.text.Html;
import android.view.View;
import android.widget.TextView;
@gelldur
gelldur / FullscreenFragment.java
Created September 11, 2015 12:48
FullscreenFragment - simple android fragment that will make fullscreen for you. Remember to: "You must manually call onKeyDown and onWindowFocusChanged."
package com.dexode.fragment;
import android.annotation.TargetApi;
import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.view.KeyEvent;
@pyricau
pyricau / IMMLeaks.java
Last active June 5, 2022 22:46
"Fix" for InputMethodManager leaking the last focused view: https://code.google.com/p/android/issues/detail?id=171190
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.content.ContextWrapper;
import android.os.Bundle;
import android.os.Looper;
import android.os.MessageQueue;
import android.util.Log;
import android.view.View;
import android.view.ViewTreeObserver;
@phatmann
phatmann / BackgroundTask.swift
Created April 15, 2015 03:14
Encapsulate iOS background tasks in a Swift class
class BackgroundTask {
private let application: UIApplication
private var identifier = UIBackgroundTaskInvalid
init(application: UIApplication) {
self.application = application
}
class func run(application: UIApplication, handler: (BackgroundTask) -> ()) {
// NOTE: The handler must call end() when it is done