Skip to content

Instantly share code, notes, and snippets.

var cv = document.getElementById('cv');
var c = cv.getContext('2d');
var txtDiv = document.getElementById('txt');
var fileBtn = document.getElementById("up-button");
var img = new Image();
img.src = 'a.jpg';
img.onload = init; // 图片加载完开始转换
fileBtn.onchange = getImg;
// 根据灰度生成相应字符
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://www.npmjs.org/install.sh | sh
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://www.npmjs.org/install.sh | sh
var githubList = [
{
name:'系统基础库',
list: [
{name:'Category/Util',
list: [
{name:'sstoolkit', owner:'soffes', desc:'一套Category类型的库,附带很多自定义控件 功能不错~'},
{name:'BlocksKit', owner:'pandamonia', desc:'将Block风格带入UIKit和Founcation'},
{name:'cocoa-helpers', owner:'enormego', desc:'一些Cocoa的扩展 2年前的工程'},
@twlkyao
twlkyao / View2Bitmap.java
Created April 14, 2019 07:51
Android Create Bitmap from View
private Bitmap loadBitmapFromView(View v) {
int w = v.getWidth();
int h = v.getHeight();
Bitmap bmp = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(bmp);
// c.drawColor(Color.WHITE);//如果不设置canvas画布为白色,则生成透明
v.layout(0, 0, w, h);
v.draw(c);
return bmp;
}
@twlkyao
twlkyao / SingletonHolder.kt
Created May 5, 2019 06:43
kotlin带参的单例
/**
* 参考https://medium.com/@BladeCoder/kotlin-singletons-with-argument-194ef06edd9e
*/
open class SingletonHolder<out T, in A>(creator: (A) -> T) {
private var creator: ((A) -> T)? = creator
@Volatile private var instance: T? = null
fun getInstance(arg: A): T {
val i = instance
if (i != null) {
@twlkyao
twlkyao / ReflectApplication.java
Created May 16, 2019 11:27
Android get application context by reflect.
import android.content.Context;
import java.lang.reflect.Method;
public class ReflectApplication {
private static Context CONTEXT;
private ReflectApplication() {
}
@twlkyao
twlkyao / AppFrontBackHelper.java
Last active May 29, 2019 06:59
Android应用前后台回调
import android.app.Activity;
import android.app.Application;
import android.os.Bundle;
/**
* 应用前后台状态监听帮助类,仅在Application中使用
* 参考:https://blog.csdn.net/bzlj2912009596/article/details/80073396
*/
public class AppFrontBackHelper {
@twlkyao
twlkyao / ActivityStackManager.java
Created May 29, 2019 07:05
获取当前的activity
import android.app.Activity;
import java.lang.ref.WeakReference;
import java.util.Stack;
/**
* 获取当前的activity
* 两种思路: 1.弱引用持有当前activity
* 2.使用栈维护所有的activity,然后获取栈顶的activity
* 参考:https://www.jianshu.com/p/77f754446009