Skip to content

Instantly share code, notes, and snippets.

Avatar

Zhang Zhibin zhangzhibin

View GitHub Profile
@zhangzhibin
zhangzhibin / install-tr-control-gitee-fixed.sh
Last active Nov 6, 2021
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/
View install-tr-control-gitee-fixed.sh
#!/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 / loadJsAsync.ts
Last active Sep 24, 2021
Dynamically load a js script and set parameters
View loadJsAsync.ts
// 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 / waitUntil.ts
Created Sep 24, 2021
javascript/typescript wait until condition meet
View waitUntil.ts
// 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 / fbig-shortcut.ts
Created Jul 16, 2021
create shortcut in Facebook Instant Game, visit https://xmanyou.com for more.
View fbig-shortcut.ts
function tryCreateShortcutAsync(){
if(!FBInstant){
console.info("FBInstant Not Available");
return;
}
console.info("Try Create shortcut");
FBInstant.canCreateShortcutAsync()
.then(function(canCreateShortcut) {
@zhangzhibin
zhangzhibin / build.gradle
Last active Jul 16, 2021
set better name for output file in android studio with build.gradle https://xmanyou.com/android-studio-build-file-with-better-name/
View build.gradle
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 / IronsourceHelper.ts
Last active Jul 27, 2021
laya + ironsource android sdk helper, contact me at https://xmanyou.com
View IronsourceHelper.ts
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 / getAdvertisingId.java
Last active May 20, 2021
query device adid for Facebook Ads Testing. contact me at https://xmanyou.com
View getAdvertisingId.java
// https://xmanyou.com
// in app gradle file
android {
// ...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
@zhangzhibin
zhangzhibin / TAHelper.java
Last active May 20, 2021
Helper for TA Android SDK, 数数科技TA 安卓SDK 调用封装。 contact me at https://xmanyou.com
View TAHelper.java
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 / FileBox.ts
Last active Dec 1, 2021
Using Open File Dialog in Cocos Creator project 详细步骤参考 https://xmanyou.com/cocos-creator-open-file-box/
View FileBox.ts
// 影子工作室为你提供详细步骤 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
@zhangzhibin
zhangzhibin / ScreenShotNode.ts
Last active Jul 16, 2019
A screenshot component for Cocos Creator 2.0.5 written in typescript
View ScreenShotNode.ts
// 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