Skip to content

Instantly share code, notes, and snippets.

View codeniko's full-sized avatar

Nikolay Feldman codeniko

View GitHub Profile
@codeniko
codeniko / Doze_Mode_Behavior.md
Created August 3, 2019 04:01 — forked from christophermark/Doze_Mode_Behavior.md
Android Marshmallow Idle Mode Behavior

What is "idle mode"?

Idle mode is a state where the phone has no network connectivity and apps are temporarily suspended. Idle mode gets triggered by one of two ways: an asleep, still, unplugged phone (Doze mode), and when an app has not been opened in a significant amount of time (App Standby Mode). During idle mode via Doze, the phone will wake up periodically for a short amount of time, allowing apps to run and use network connectivity. Using several different methods outlined below, it is possible to wake apps up during idle mode outside of these maintenance windows.

Time to enter Doze mode

1 hour of being still after the screen turns off.

Time to enter App Standby mode

TBD

Idle maintenance windows

@codeniko
codeniko / Local PR test and merge.md
Created August 14, 2018 04:39 — forked from adam-p/Local PR test and merge.md
Testing a pull request, then merging locally; and avoiding TOCTOU

It's not immediately obvious how to pull down the code for a PR and test it locally. But it's pretty easy. (This assumes you have a remote for the main repo named upstream.)

Getting the PR code

  1. Make note of the PR number. For example, Rod's latest is PR #37: Psiphon-Labs/psiphon-tunnel-core#37

  2. Fetch the PR's pseudo-branch (or bookmark or rev pointer whatever the word is), and give it a local branch name. Here we'll name it pr37:

$ git fetch upstream pull/37/head:pr37
@codeniko
codeniko / README.md
Last active April 26, 2018 08:46 — forked from jed/LICENSE.txt
generate random UUIDs

UUID

Returns a random v4 UUID of the form xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx, where each x is replaced with a random hexadecimal digit from 0 to f, and y is replaced with a random hexadecimal digit from 8 to b.

There's also @LeverOne's approach using iteration, which is one byte shorter.

@codeniko
codeniko / gist:c6f7ca9992b938d8d561cb8a7b76ed3b
Created December 8, 2016 22:32 — forked from cdown/gist:1163649
Bash urlencode and urldecode
urlencode() {
# urlencode <string>
old_lc_collate=$LC_COLLATE
LC_COLLATE=C
local length="${#1}"
for (( i = 0; i < length; i++ )); do
local c="${1:i:1}"
case $c in
[a-zA-Z0-9.~_-]) printf "$c" ;;
@codeniko
codeniko / AsyncController.diff
Created December 1, 2016 01:32 — forked from jriecken/AsyncController.diff
Contextual Logging
import play.api.Logger
import org.slf4j.MDC
+import scala.concurrent.{ExecutionContext, Future}
import java.util.UUID
+import java.util.concurrent.Executors
-object SyncController extends Controller {
- def syncEndpoint(profileId: Long) = Action(parse.json) { req =>
+object AsyncController extends Controller {
+ implicit val ec = ExecutionContext.fromExecutor(Executors.newFixedThreadPool(2))
+ // For this example, ensure the threads in the pool are already created