Skip to content

Instantly share code, notes, and snippets.

View nhancv's full-sized avatar
🏠
Working from home

Nhan Cao nhancv

🏠
Working from home
View GitHub Profile
allprojects {
repositories {
jcenter()
maven { url "http://192.168.1.124:8081/repository/maven-releases/" }
}
}
apply plugin: 'maven'
uploadArchives {
repositories {
mavenDeployer {
repository(url: "http://192.168.1.124:8081/repository/maven-releases/") {
authentication(userName: "admin", password: "admin123")
pom.groupId = "com.beesightsoft.caf"
pom.artifactId = "rx"
pom.version = '2.0.0'
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_152.jdk/Contents/Home
export PATH=$JAVA_HOME/bin:$PATH
@nhancv
nhancv / AndroidMockitoPresenterTest.java
Created October 17, 2017 04:15
Android mockito samples
package com.nhancv.training;
import com.nhancv.training.main.MainPresenter;
import com.nhancv.training.main.MainView;
import com.nhancv.training.main.ObjectBus;
import org.greenrobot.eventbus.EventBus;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@nhancv
nhancv / MainActivity.java
Created November 14, 2017 04:10
genBitmapFile for view offscreen
public static void genBitmapFile(Context context, View targetView, int num) {
int sizePixels = 1080;
Bitmap result = Bitmap.createBitmap(sizePixels, sizePixels, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(result);
// measure view first
int sizeSpec = View.MeasureSpec.makeMeasureSpec(sizePixels, View.MeasureSpec.EXACTLY);
targetView.measure(sizeSpec, sizeSpec);
@nhancv
nhancv / MainActivity.java
Created November 14, 2017 04:11
saveBitmapToFile
public static File saveBitmapToFile(Context context, String filename, Bitmap bitmap) {
File f = new File(context.getCacheDir(), filename);
Log.e(TAG, "saveBitmapToFile: " + f.getAbsolutePath());
try {
f.createNewFile();
//Convert bitmap to byte array
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 0 /*ignored for PNG*/, bos);
byte[] bitmapdata = bos.toByteArray();
@nhancv
nhancv / build.gradle
Created November 17, 2017 03:45
build.gradle for kotlin
group 'com.beesightsoft.kotlin'
version '1.0-SNAPSHOT'
buildscript {
ext.kotlin_version = '1.1.60'
repositories {
mavenCentral()
}
dependencies {
@nhancv
nhancv / version-ios.sh
Last active May 15, 2023 16:51
React native: Bash script to update Info.plist version
#!/usr/bin/env bash -e
_PROJECT_NAME=$(cat package.json | grep name | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[[:space:]]')
_INFOPLIST_DIR="ios/${_PROJECT_NAME}/Info.plist"
_PACKAGE_VERSION=$(cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[[:space:]]')
# Set BUILD_NUMBER to the value 1 only if it is unset.
: ${BUILD_NUMBER=$(expr $(git log -1 --pretty=format:%ct) / 3600)}
@nhancv
nhancv / build.gradle
Last active December 6, 2017 10:25
React native: Gradle android version strategy (android/app/build.gradle)
import groovy.json.JsonSlurper
def getNpmVersion() {
def inputFile = new File("../package.json")
def packageJson = new JsonSlurper().parseText(inputFile.text)
return packageJson["version"]
}
def getCommitTime() {
return (Integer) (Long.valueOf('git log -1 --pretty=format:%ct'.execute().getText().trim())/3600)
}
@nhancv
nhancv / express-dealwith-client-interrupt-connection.js
Created January 2, 2018 10:43
ExpressJs: Deal with client interrupt connection
const express = require('express')
const app = express()
app.get('/', (req, res) => {
var connectionInterrupt = false;
var str = "a hihi do ngoc." + new Date().getTime()
console.log("Process: " + str);
req.connection.on('close',function(){