Skip to content

Instantly share code, notes, and snippets.

View zhangzhibin's full-sized avatar

Zhang Zhibin zhangzhibin

View GitHub Profile
@zhangzhibin
zhangzhibin / ScreenShotNode.ts
Last active July 16, 2019 12:59
A screenshot component for Cocos Creator 2.0.5 written in typescript
// https://xmanyou.com/cocos-creator-jie-tu-gong-neng-dai-ma/
// 截图组件 (如果没有提前添加Camera组件,则会自动添加一个默认参数的Camera)
// 语言:Typescript
// Cocos Creator 版本: 2.0.5
// 使用方法:
// 1. 在场景里添加一个Node, 把这个组件拖进去
// 2. 在需要截图的地方,import, 然后调用:ScreenShotNode.take()
// Screenshot component
// typescript
@zhangzhibin
zhangzhibin / TAHelper.java
Last active May 20, 2021 10:32
Helper for TA Android SDK, 数数科技TA 安卓SDK 调用封装。 contact me at https://xmanyou.com
package sdkhelper;
import android.content.Context;
import android.util.Log;
import com.adjust.sdk.Adjust;
import org.json.JSONObject;
import java.util.ArrayList;
@zhangzhibin
zhangzhibin / getAdvertisingId.java
Last active May 20, 2021 10:32
query device adid for Facebook Ads Testing. contact me at https://xmanyou.com
// https://xmanyou.com
// in app gradle file
android {
// ...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
@zhangzhibin
zhangzhibin / build.gradle
Last active July 16, 2021 06:46
set better name for output file in android studio with build.gradle https://xmanyou.com/android-studio-build-file-with-better-name/
defaultConfig {
applicationId "com.xmanyou.my.game"
minSdkVersion 21
targetSdkVersion 30
versionCode 28
versionName "1.2.5"
def gitCommit = "git rev-parse --short HEAD".execute().text.trim()
archivesBaseName = "${defaultConfig.applicationId}-${defaultConfig.versionName}v${defaultConfig.versionCode}-${gitCommit}"
println 'outputFileName: after = ' + archivesBaseName
@zhangzhibin
zhangzhibin / fbig-shortcut.ts
Created July 16, 2021 08:14
create shortcut in Facebook Instant Game, visit https://xmanyou.com for more.
function tryCreateShortcutAsync(){
if(!FBInstant){
console.info("FBInstant Not Available");
return;
}
console.info("Try Create shortcut");
FBInstant.canCreateShortcutAsync()
.then(function(canCreateShortcut) {
@zhangzhibin
zhangzhibin / IronsourceHelper.ts
Last active July 27, 2021 02:06
laya + ironsource android sdk helper, contact me at https://xmanyou.com
module SdkHelper{
export class IronSourceHelper{
public static ironsource:Laya.IPlatformClass;
public static init(){
if(!this.ironsource){
this.ironsource = Laya.PlatformClass.createClass("sdkhelper.IronSourceHelper");
}
let js1 = `window["IronSourceHelper"].onInterstitialReadyChange(%s)`;
@zhangzhibin
zhangzhibin / waitUntil.ts
Created September 24, 2021 01:31
javascript/typescript wait until condition meet
// TypeScript/JavaScript 异步等待方法的实现
// refer to https://xmanyou.com/javascript-wait-until-condition-meet-or-timeout/
function waitUntil(condition:()=>boolean, timeout?:number, interval?:number) {
if (timeout === void 0) { timeout = 0; } // if not set, wait forever
if (interval === void 0) { interval = 50; } // default interval = 50ms
let waitHandler;
let timeoutHandler;
return new Promise<void>(function (resolve, reject) {
var waitFn = function () {
if (condition()) {
@zhangzhibin
zhangzhibin / loadJsAsync.ts
Last active September 24, 2021 04:46
Dynamically load a js script and set parameters
// JavaScript 根据需要动态加载脚本并设置参数
// refer to https://xmanyou.com/javascript-dynamically-load-script-and-set-parameters/
async function loadJsAsync(src:string, async:boolean=false, options?:any) {
return new Promise<void>((resolve, reject) => {
const script = document.createElement('script');
script.src = src;
script.async = async;
if(options) {
for(const key in options) {
// script[key] = options[key];
@zhangzhibin
zhangzhibin / install-tr-control-gitee-fixed.sh
Last active February 18, 2023 16:34
fixed install-tr-control script to overcome the installation error: cp: cannot stat '/tmp/tr-web-control/transmission-web-control-version/src/.': No such file or directory, refer to https://xmanyou.com/transmission-web-control-error-404-not-found/
#!/bin/bash
# 获取第一个参数
ARG1="$1"
ROOT_FOLDER=""
SCRIPT_NAME="$0"
SCRIPT_VERSION="1.2.3"
VERSION=""
WEB_FOLDER=""
ORG_INDEX_FILE="index.original.html"
INDEX_FILE="index.html"
@zhangzhibin
zhangzhibin / FileBox.ts
Last active August 31, 2023 10:38
Using Open File Dialog in Cocos Creator project 详细步骤参考 https://xmanyou.com/cocos-creator-open-file-box/
// 影子工作室为你提供详细步骤 https://xmanyou.com/cocos-creator-open-file-box/
const {ccclass, property} = cc._decorator;
@ccclass
export default class FileBox extends cc.Component {
// LIFE-CYCLE CALLBACKS:
@property
containerId = "_filebox_container_";
@property