Skip to content

Instantly share code, notes, and snippets.

View kibotu's full-sized avatar
🎯
Focusing

Jan Rabe kibotu

🎯
Focusing
View GitHub Profile
@kibotu
kibotu / UnityGetNativeAndroidVersion
Last active September 6, 2023 16:27
Get versionCode and versionName with unity.
//int vesioncode = context().getPackageManager().getPackageInfo(context().getPackageName(), 0).versionCode;
public static int GetVersionCode() {
AndroidJavaClass contextCls = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject context = contextCls.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaObject packageMngr = context.Call<AndroidJavaObject>("getPackageManager");
string packageName = context.Call<string>("getPackageName");
AndroidJavaObject packageInfo = packageMngr.Call<AndroidJavaObject>("getPackageInfo", packageName, 0);
return packageInfo.Get<int>("versionCode");
}
@kibotu
kibotu / gist:1278883c19810f40f2c4
Created September 17, 2014 13:10
should_verify_response()
[Test]
public function should_verify_response():void {
// @see https://manage.sbs.wooga.com/docs/api/abconfig
// 1) Decrypt the X-SBS-Config-Signature using the public key for your SBS-ID
var rsa:RSAKey = PEM.readRSAPublicKey(correctKey);
var src:ByteArray = new ByteArray();
src.writeUTFBytes(Base64.encode(correctSignature));
@kibotu
kibotu / Sierpinski.java
Created September 20, 2014 12:49
Sierpinski Triangle and Carpet
package klausur.spierpinski;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.awt.*;
import static javax.swing.JFrame.EXIT_ON_CLOSE;
/*
* OpenSimplex (Simplectic) Noise in Java.
* (v1.0.1 With new gradient set and corresponding normalization factor, 9/19/14)
*/
public class OpenSimplexNoise {
private static final double STRETCH_CONSTANT_3D = -1.0 / 6;
private static final double SQUISH_CONSTANT_3D = 1.0 / 3;
@kibotu
kibotu / CSVParser
Last active May 3, 2018 07:51
CSVParser
public static class CSVParser
{
public static string ReadKeyStorePassword (string path)
{
string password = "";
StreamReader theReader = new StreamReader (path, Encoding.Default);
using (theReader) {
password = theReader.ReadLine ().Replace ("\n", "");
}
@kibotu
kibotu / gist:5745d401f26aec4e13cc
Created November 17, 2014 10:54
Unlock Achievement with Promises
public override Promise unlockAchievements (string name, double points, bool autoStart = true)
{
var deferred = new Deferred<bool>();
string format = "Unlock Achievement " + name + " with " + points;
deferred.OnFulfilled += (bool result) => Debug.Log(format + ": " + result);
deferred.OnFailed += (bool result) => Debug.Log(format + ": " + result);
deferred.action += () =>
Social.ReportProgress(name, points, (bool success) => {
if(success)
@kibotu
kibotu / Extensions
Created December 18, 2014 15:56
IEnumerable ToString with separator extension method
public static string ToString<T>(this IEnumerable<T> list, string separator)
{
StringBuilder sb = new StringBuilder();
foreach (var obj in list) {
if (sb.Length > 0) {
sb.Append(separator);
}
sb.Append(obj);
}
return sb.ToString();
@kibotu
kibotu / extension
Created January 29, 2015 10:20
get component by interface from gameobject
public static T GetComponentByInterface<T>(this GameObject go) where T : class
{
var components = go.GetComponents<MonoBehaviour>();
foreach (var c in components)
{
T t = c as T;
if (t != null)
return t;
}
return null;
@kibotu
kibotu / build.gradle
Last active May 1, 2018 11:01
gradle build increases android versionName and versionCode automatically
// major.branchName.revId.commitCount
def pattern = Pattern.compile('versionName=\"(\\d+)\\.(\\w+)\\.(\\w+)\\.(\\d+)\"')
task incrementMajor << {
def stdout = new ByteArrayOutputStream()
exec {
commandLine "git", "branch"
@kibotu
kibotu / WebViewClient
Last active February 13, 2023 03:27
Android WebView: resource interception and replacement by local resource
mWebView.setWebViewClient(new WebViewClient() {
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
if (url.contains("creditcard_cvc.jpg")) {
Log.v("WebView", "Replacing [" + url + "] with [R.raw.tmp_replacement]");
ContentResolver contentResolver = getActivity().getContentResolver();
return new WebResourceResponse(contentResolver.getType(Uri.parse(url)), "UTF-8", getResources().openRawResource(R.raw.tmp_replacement));
}
return super.shouldInterceptRequest(view, url);