Skip to content

Instantly share code, notes, and snippets.

@pete911
pete911 / input stream to string
Created February 9, 2012 10:27
java - input stream to string (one liner)
return new Scanner(is).useDelimiter("\\A").next();
@mbinna
mbinna / include-version-info.sh
Last active November 12, 2021 20:59
Include Version Info from Git into Info.plist at build time
Add the script include-version-info.sh into a new run script build phase of your application target. The build phase
should be located after the build phase "Copy Bundle Resources".
@ktuite
ktuite / UniqueId.java
Created December 3, 2012 03:08
Generating and storing a random, unique user id to track unique installations of an android app.
// adaptation of: http://android-developers.blogspot.com/2011/03/identifying-app-installations.html
// but using shared preferences instead of a file: http://developer.android.com/reference/android/content/SharedPreferences.html
// here's a better look at using shared preferences: http://developer.android.com/guide/topics/data/data-storage.html#pref
public class UniqueId {
private static String sID = null;
private static final String SHARED_PREF_KEY = "SKETCHABIT2";
private static final String ID_KEY = "id";
@fdoyle
fdoyle / CameraManager.java
Last active May 30, 2016 17:55
This is a stripped down version of the CameraManager class used in the Android stock camera
package com.wta.videodemo;
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
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);
@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);
@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)/%=%)

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:

@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,
@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 <a.j.buxton@gmail.com>
from bluepy import btle
import time
class BB8(btle.DefaultDelegate):
def __init__(self, deviceAddress):