Skip to content

Instantly share code, notes, and snippets.

View bholota's full-sized avatar

Bartłomiej Hołota bholota

View GitHub Profile
@bholota
bholota / Logger.cs
Last active November 24, 2015 21:31
Fire and forget Unity3d remote logger for mobile (Android/iOS) devices
using UnityEngine;
using System.Collections;
public class Logger : MonoBehaviour
{
public static string URL = "XXX";
void Start()
{
@bholota
bholota / TextUtils.java
Created January 12, 2016 14:39
Sets regular font face for regex matches and light one for rest
private Spannable setLightHeaderText(String text, String regexPattern) {
final Pattern regPattern = Pattern.compile(regexPattern);
final Matcher matches = regPattern.matcher(text);
final Spannable spannable = new SpannableString(text);
// right now we use first only occurrence if exist
if (!matches.find()) {
final CustomTypeFaceSpan lightSpanStart = new CustomTypeFaceSpan("roboto-light");
spannable.setSpan(lightSpanStart, 0, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
return spannable;
Index: spoon-runner/src/main/java/com/squareup/spoon/SpoonDeviceRunner.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- spoon-runner/src/main/java/com/squareup/spoon/SpoonDeviceRunner.java (revision 0e7361ea1c2926d3953a37a4f62357bc94dde3e2)
+++ spoon-runner/src/main/java/com/squareup/spoon/SpoonDeviceRunner.java (revision )
@@ -61,6 +61,7 @@
private final List<String> instrumentationArgs;
private final String className;
@bholota
bholota / BaristaUtils.java
Created May 31, 2016 12:28
Wake up before UI test
public final class BaristaUtils {
public static void wakeUp() {
InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
@Override
public void run() {
Window window = new ComponentFinder().findCurrentActivity().getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
@bholota
bholota / Utils.java
Created August 11, 2016 10:07
WannaBeFunctional
private static abstract class Transform1<T, M> {
abstract M transform(T input);
}
private <InputType, OutputType, InputList extends List<InputType>, OutputList extends List<OutputType>> OutputList map (InputList input, Transform1<InputType, OutputType> transform1) {
List<OutputType> out = new ArrayList<>();
for (InputType i : input) {
out.add(transform1.transform(i));
}
@bholota
bholota / GetterSetterTemplate.java
Created December 14, 2016 15:28
InteliJ getter/setter template for Jackson properties
// JacksonGetter
#set($const_name = $helper.getPropertyName($field, $project).toString().replaceAll("([A-Z]+)","\_$1").toUpperCase())
@JsonProperty(${const_name})
@Nullable
#if($field.modifierStatic)
static ##
#end
$field.type ##
#set($name = $StringUtil.capitalizeWithJavaBeanConvention($StringUtil.sanitizeJavaIdentifier($helper.getPropertyName($field, $project))))
#if ($field.boolean && $field.primitive)
public class BitmapUtils {
public static Bitmap cropCircleCenterBitmap(Bitmap bitmap) {
int size;
int x;
int y;
// calculate square bitmap
if (bitmap.getWidth() >= bitmap.getHeight()) {
x = bitmap.getWidth() / 2 - bitmap.getHeight() / 2;
y = 0;
size = bitmap.getHeight();
import android.app.Activity
import android.support.annotation.IdRes
import android.view.View
fun <T : View> Activity.bind(@IdRes idRes: Int): Lazy<T> {
@Suppress("UNCHECKED_CAST")
return unsafeLazy { findViewById(idRes) as T }
}
fun <T : View> View.bind(@IdRes idRes: Int): Lazy<T> {
#include <iostream>
#include <fstream>
int main() {
std::fstream plik;
bool pierwszy = true;
if (pierwszy) {
plik.open("file_load.cpp", std::ios::in);
} else {
plik.open("file_load.cpp", std::ios::in);
"""Script for converting PacktPub ebooks names in current directory.
Usage:
To execute just put script in ebook directory (subdirs will not work).
Todo:
- Detect unsupported or already converted file names.
"""
#!/usr/bin/python3
#-*- encoding: utf-8 -*-