Skip to content

Instantly share code, notes, and snippets.

@danielgalasko
danielgalasko / RepeatingTimer.swift
Last active September 5, 2024 07:07
A repeating GCD timer that can run on a background queue
/// RepeatingTimer mimics the API of DispatchSourceTimer but in a way that prevents
/// crashes that occur from calling resume multiple times on a timer that is
/// already resumed (noted by https://github.com/SiftScience/sift-ios/issues/52
class RepeatingTimer {
let timeInterval: TimeInterval
init(timeInterval: TimeInterval) {
self.timeInterval = timeInterval
}
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// by calling [NSURLProtocol registerClass:[MyURLProtocol class]]; in -application:didFinishLoadingWithOptions:, your protocol will have priority over any of the built-in protocols.
URLProtocol.registerClass(ActivityURLProtocol.self)
//URLProtocol.unregisterClass(ActivityURLProtocol.self)
print(URLSession.shared.configuration.protocolClasses)
}
@mortehu
mortehu / zip-test.cc
Last active May 23, 2022 12:00
C++ zip
#include <cstdio>
#include <list>
#include <vector>
#include "zip.h"
int main() {
std::vector<int> one{{1, 11}};
auto two = [] { return std::vector<short>{{2, 22}}; };
const std::list<float> three{{3, 33}};
@ctrl-freak
ctrl-freak / android-adb-pull-apk.md
Last active May 1, 2025 03:27
Retrieve APK from Non-Rooted Android Device through ADB

https://stackoverflow.com/a/18003462/348146

None of these suggestions worked for me, because Android was appending a sequence number to the package name to produce the final APK file name (this may vary with the version of Android OS). The following sequence of commands is what worked for me on a non-rooted device:

  1. Determine the package name of the app, e.g. com.example.someapp. Skip this step if you already know the package name.

    adb shell pm list packages

    Look through the list of package names and try to find a match between the app in question and the package name. This is usually easy, but note that the package name can be completely unrelated to the app name. If you can't recognize the app from the list of package names, try finding the app in Google Play using a browser. The URL for an app in Google Play contains the package name.

@ali1234
ali1234 / bb8.py
Created October 17, 2015 15:47
Control Sphero BB-8 from Linux.
#!/usr/bin/env python
# BB-8 Python driver by Alistair Buxton <[email protected]>
from bluepy import btle
import time
class BB8(btle.DefaultDelegate):
def __init__(self, deviceAddress):
@Shaked
Shaked / CroppingTool.java
Last active June 6, 2024 08:07
Android Camera
public class CroppingTool {
private static final String TAG = "CroppingTool";
public static byte[] cropRect(
byte data[],
int previewTop,
int previewLeft,
int previewBottom,
int previewRight,
int gridRight,

CLang optimizations on Mac OSX

Version:

Apple LLVM version 6.0 (clang-600.0.57) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.1.0
Thread model: posix

This was made with commands:

@darkdukey
darkdukey / Android.mk
Last active December 10, 2022 14:31
NDK build include all the files under a directory
#traverse all the directory and subdirectory
define walk
$(wildcard $(1)) $(foreach e, $(wildcard $(1)/*), $(call walk, $(e)))
endef
#find all the file recursively under jni/
ALLFILES = $(call walk, $(LOCAL_PATH))
FILE_LIST := $(filter %.cpp, $(ALLFILES))
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)
@shi-yan
shi-yan / keepalive
Created September 17, 2014 23:36
Correct way to set tcp socket keepalive on Win, Mac and Linux. Verified with Wireshark.
void setTcpKeepalive(SOCKET &sockfd)
{
const uint32_t keepaliveIntervalSec = 10;
#ifdef _WIN32
tcp_keepalive keepaliveParams;
DWORD ret = 0;
keepaliveParams.onoff = 1;
keepaliveParams.keepaliveinterval = keepaliveParams.keepalivetime = keepaliveIntervalSec * 1000;
WSAIoctl(sockfd, SIO_KEEPALIVE_VALS, &keepaliveParams, sizeof(keepaliveParams), NULL, 0, &ret, NULL, NULL);
public class Dexter {
private static String optimizedDirectory = "optimized";
private static String workDirectory = "working";
public static void loadFromAssets(Context context, String fileName) throws Exception {
File optimized = new File(optimizedDirectory);
optimized = context.getDir(optimized.toString(), Context.MODE_PRIVATE);
optimized = new File(optimized, fileName);