Skip to content

Instantly share code, notes, and snippets.

@ziglee
ziglee / RestJsonClient.java
Created December 23, 2011 16:40
Android Rest Json Client
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
@ziglee
ziglee / AndroidKeyHash.java
Created May 18, 2012 16:38
Android Key Hash
PackageInfo info = getPackageManager().getPackageInfo("<your_package_name>", PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.d("Hash Key:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
@ziglee
ziglee / routes.js
Last active August 21, 2021 15:05
Listing all Costumers with birthday today or tomorrow using Sequelize.js.
router.get('/api/birthday', function (req, res, next) {
var month = moment().month() + 1;
var today = moment().date();
var tomorrow = moment().add(1, 'days').date();
Costumer.findAll({
attributes: ['id','name','birthDate'],
where: {
$and: [
sequelize.where(sequelize.fn('month', sequelize.col("birth_date")), month)
],
import android.text.TextUtils;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.net.SocketTimeoutException;
import javax.net.ssl.HttpsURLConnection;
import br.com.experience.hsm.data.entity.ErrorEntity;
package br.com.celg.pd318
class StudsUtil {
static enum SeqPosition {
START,
MIDDLE,
END
}
@ziglee
ziglee / disablebuildcache.groovy
Last active January 12, 2018 12:45
Disable android build chache in gradle properties
File propsFile = new File('./gradle.properties')
if (!propsFile.exists()) {
propsFile.withWriterAppend { w -> w << 'android.enableBuildCache = false' }
} else {
Properties props = new Properties()
props.load(propsFile.newDataInputStream())
props.setProperty('android.enableBuildCache', 'false')
props.store(propsFile.newWriter(), null)
}
@ziglee
ziglee / build.gradle
Created January 12, 2018 13:47
Build gradle excerpt that uses Jenkins BUILD_NUMBER to compose the versionCode in AndroidManifest.xml
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.25.1'
}
}
apply plugin: 'com.android.application'
@ziglee
ziglee / sonarqube-docker-compose.yml
Created March 7, 2018 17:37
Sonarqube + PostgreSQL (Docker Compose)
version: "2"
services:
sonarqube:
image: sonarqube:6.7.1
ports:
- "9000:9000"
networks:
- sonarnet
environment:
@ziglee
ziglee / config.yml
Last active March 14, 2018 17:13
CircleCI android + sonarqube scanner
version: 2
jobs:
build:
dependencies:
pre:
- echo y | android update sdk --no-ui --all --filter "com.android.tools.build:gradle:3.0.1"
docker:
- image: circleci/android:api-26-alpha
environment:
JVM_OPTS: -Xmx3200m
@ziglee
ziglee / TestDataStore.kt
Created January 12, 2023 12:07
"multiple instances" error when removing value during unit testing
import android.content.Context
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.PreferenceDataStoreFactory
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.stringPreferencesKey
import androidx.datastore.preferences.preferencesDataStoreFile
import androidx.test.core.app.ApplicationProvider
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.ExperimentalCoroutinesApi