text:
@class NSObject<OS_dispatch_queue>, NSString, NSURLSession, NSURLSessionDownloadTask;

@interface WADownloadFileTask : NSObject
{
    NSString *_appID;
    NSObject<OS_dispatch_queue> *_workerQueue;
    NSURLSession *_urlSession;
    NSURLSessionDownloadTask *_task;
    CDUnknownBlockType _completionHandler;
    _Bool _isRedirectInvalid;
    NSString *_url;
    _Bool _isExceedMaxFileSize;
    _Bool _isCanceled;
    id <WADownloadFileTaskDelegate> delegate;
    NSString *_savePath;
    NSString *_localID;
}

@property _Bool isCanceled; // @synthesize isCanceled=_isCanceled;
@property(retain) NSString *localID; // @synthesize localID=_localID;
@property(retain) NSString *savePath; // @synthesize savePath=_savePath;
@property _Bool isExceedMaxFileSize; // @synthesize isExceedMaxFileSize=_isExceedMaxFileSize;
@property __weak id <WADownloadFileTaskDelegate> delegate; // @synthesize delegate;
- (void).cxx_destruct;
- (void)taskDidEnd;
- (id)workerQueue;
- (void)callCompletionHandlerWithLocalID:(id)arg1 statusCode:(long long)arg2 error:(id)arg3;
- (void)setCompletionHandler:(CDUnknownBlockType)arg1;
- (void)markRedirectFail;
- (id)task;
- (void)cancelWithError:(id)arg1;
- (void)cancelForExceedMaxSize;
- (void)cancel;
- (void)taskDidCompleteWithError:(id)arg1 statusCode:(unsigned long long)arg2;
- (void)anyThread_didFinishDownloadingToURL:(id)arg1 mimeType:(id)arg2;
- (void)startWithURL:(id)arg1 httpHeaders:(id)arg2 userAgent:(id)arg3 referer:(id)arg4 completionHandler:(CDUnknownBlockType)arg5;
- (void)dealloc;
- (id)initWithAppID:(id)arg1 urlSession:(id)arg2 workerQueue:(id)arg3;

@end


text:
var Zipkin = Zipkin || {};

Zipkin.Span = (function(superClass) {

  var Span = function(config) {
    Zipkin.Util.bind(this, superClass.prototype.constructor)(config);
    this.traceId       = config.traceId;
    this.startTime     = config.startTime;
    this.endTime       = config.endTime;
    this.duration      = config.duration;
    this.services      = config.services || [];
    this.annotations   = config.annotations || [];
    this.kvAnnotations = config.kvAnnotations || [];
  };

  jQuery.extend(Span.prototype, superClass.prototype);

  Span.prototype.getTraceId       = function() { return this.traceId; };
  Span.prototype.getStartTime     = function() { return this.startTime; };
  Span.prototype.getEndTime       = function() { return this.endTime; };
  Span.prototype.getDuration      = function() { return this.duration; };
  Span.prototype.getServices      = function() { return this.services; };
  Span.prototype.getAnnotations   = function() { return Zipkin.Util.shallowCopy(this.annotations); };
  Span.prototype.getKvAnnotations = function() { return Zipkin.Util.shallowCopy(this.kvAnnotations); };

  Span.prototype.setTraceId       = function(id)   { this.traceId = id; };
  Span.prototype.setStartTime     = function(s)    { this.startTime = s; };
  Span.prototype.setEndTime       = function(e)    { this.endTime = e; };
  Span.prototype.setDuration      = function(d)    { this.duration = d; };
  Span.prototype.setServices      = function(s)    { this.services = s; };
  Span.prototype.setAnnotations   = function(a)    { this.annotations = a; };
  Span.prototype.setKvAnnotations = function(kvAs) { this.kvAnnotations = kvAs; };

  Span.prototype.addAnnotation    = function(a) { this.annotations.push(a); };
  Span.prototype.addKvAnnotation  = function(a) { this.kvAnnotations.push(a); };

  Span.prototype.getServiceName = function() {
    if (this.services.length === 0) {
      return "Unknown";
    }
    this.services.sort();
    return this.services.join(", ");
  };

  Span.prototype.getAll = function() {
    return jQuery.extend(
      Zipkin.Util.bind(this, superClass.prototype.getAll)(),
      {
        traceId       : this.getTraceId(),
        startTime     : this.getStartTime(),
        endTime       : this.getEndTime(),
        duration      : this.getDuration(),
        services      : this.getServices(),
        annotations   : this.getAnnotations(),
        kvAnnotations : this.getKvAnnotations()
      }
    );
  };

  return Span;
})(Zipkin.Node);

Zipkin.fromRawSpan = function(rawSpan) {
  var span = new Zipkin.Span({
    id            : rawSpan.id,
    parentId      : rawSpan.parentId,
    name          : rawSpan.name,
    children      : [],

    traceId       : rawSpan.traceId,
    startTime     : rawSpan.startTime,
    endTime       : rawSpan.startTime + rawSpan.duration,
    duration      : rawSpan.duration,
    services      : rawSpan.services,
    annotations   : [],
    kvAnnotations : [],
  });
  var annotations = $.map(rawSpan.annotations, function(a) {
    var ann = Zipkin.fromRawAnnotation(a);
    ann.setSpan(span);
    return ann;
  });
  var kvAnnotations = $.map(rawSpan.binaryAnnotations, function(b) {
    var ann =  Zipkin.fromRawKvAnnotation(b);
    ann.setSpan(span);
    return ann;
  });
  span.setAnnotations(annotations);
  span.setKvAnnotations(kvAnnotations);
  return span;
};

redpajama_set_name: RedPajamaGithub


text:
package com.easypost.fixtures.components;

import com.google.gson.annotations.SerializedName;

import java.util.HashMap;

public final class Users {
    @SerializedName("referral")
    public HashMap<String, Object> referral;

}


text:
package com.example.viewpager.util;

import android.app.Application;

import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.Volley;

public class App extends Application {
	public static ImageLoader imageLoader;
	public static BitmapCache bitmapCache;
	@Override
	public void onCreate() {
		// TODO Auto-generated method stub
		super.onCreate();
		bitmapCache = new BitmapCache();
		imageLoader = new ImageLoader(Volley.newRequestQueue(getApplicationContext()), bitmapCache);
	}
}


text:
package com.returntrue.util.ui;

import android.content.ContentValues;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.LightingColorFilter;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.provider.MediaStore;
import android.util.Base64;
import android.util.Log;
import android.widget.ImageView;

import com.returntrue.application.BaseApplication;
import com.returntrue.framework.JActivity;
import com.returntrue.util.JLog;

import org.apache.http.util.ByteArrayBuffer;

import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.text.DecimalFormat;
import java.text.NumberFormat;

/**
 * @author JosephWang
 */
public class ImageUtil
{
    public static int MAX_LENGTH = 1280;

    public static int getResourceByName(Context context, String drawableName)
    {
        String uri = "drawable/" + drawableName;
        int res = context.getResources().getIdentifier(uri, null, context.getPackageName());
        return res;
    }

    /**
     * @param context
     * @param drawableName
     * @return
     */
    public Drawable getDrawableByName(Context context, String drawableName)
    {
        int imageResource = getResourceByName(context, drawableName);
        if (imageResource != 0)
        {
            Drawable image = context.getResources().getDrawable(imageResource);
            return image;
        }
        else
        {
            return null;
        }
    }

    /**
     * @param uri
     * @return
     * @throws Exception
     */
    public Bitmap loadBitmap(String uri) throws Exception
    {
        if (uri.startsWith("http"))
        {
            return loadBitmap(new URL(uri));
        }
        else
        {
            return loadBitmap(new File(uri));
        }
    }

    /**
     * @param uri
     * @return
     * @throws Exception
     */
    public Bitmap loadBitmap(String uri, int maxLength) throws Exception
    {
        if (uri.startsWith("http"))
        {
            return loadBitmap(new URL(uri));
        }
        else
        {
            return loadBitmap(new File(uri), maxLength);
        }
    }

    /**
     * @param url
     * @return
     * @throws Exception
     */
    public Bitmap loadBitmap(URL url) throws Exception
    {
        return loadBitmap(url, true);
    }

    /**
     * @param url
     * @return
     * @throws Exception
     */
    public Bitmap loadBitmap(URL url, boolean sampling) throws Exception
    {
        if (sampling)
        {
            return sampling(url);
        }
        else
        {
            Bitmap bitmap = null;
            try
            {
                HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                conn.setConnectTimeout(10000);
                conn.setReadTimeout(20000);
                conn.setInstanceFollowRedirects(true);
                conn.setDoInput(true);
                conn.setDoOutput(false);
                conn.connect();
                InputStream is = conn.getInputStream();

                bitmap = BitmapFactory.decodeStream(is);
                conn.disconnect();
                //bitmap = BitmapFactory.decodeStream(instream);
            }
            catch (Exception e)
            {
                Log.e("grandroid", null, e);
                throw e;
            }
            return bitmap;
        }
    }

    /**
     * @param file
     * @return
     * @throws FileNotFoundException
     */
    public Bitmap loadBitmap(File file) throws FileNotFoundException
    {
        if (file.exists())
        {
            return sampling(file);
            //return BitmapFactory.decodeFile(file.getAbsolutePath());
        }
        else
        {
            Log.e("grandroid", "can't load " + file.getAbsolutePath());
            throw new FileNotFoundException();
        }
    }

    /**
     * @param file
     * @return
     * @throws FileNotFoundException
     */
    public Bitmap loadBitmap(File file, int maxLength) throws FileNotFoundException
    {
        if (file.exists())
        {
            return sampling(file, maxLength);
            //return BitmapFactory.decodeFile(file.getAbsolutePath());
        }
        else
        {
            Log.e("grandroid", "can't load " + file.getAbsolutePath());
            throw new FileNotFoundException();
        }
    }

    /**
     * @return
     * @throws Exception
     */
    public Bitmap sampling(URL url) throws Exception
    {
        Bitmap bitmap = null;
        try
        {
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            HttpURLConnection.setFollowRedirects(true);
            conn.setConnectTimeout(10000);
            conn.setDoInput(true);
            conn.connect();
            InputStream is = conn.getInputStream();
            BitmapFactory.Options o = new BitmapFactory.Options();
            o.inJustDecodeBounds = true;
            BitmapFactory.decodeStream(is, null, o);
            //is.close();
            //Find the correct scale value. It should be the power of 2.

            int width_tmp = o.outWidth, height_tmp = o.outHeight;
            int scale = 1;
            while (true)
            {
                if (width_tmp <= MAX_LENGTH && height_tmp <= MAX_LENGTH)
                {
                    break;
                }
                width_tmp /= 2;
                height_tmp /= 2;
                scale *= 2;
            }

            //decode with inSampleSize
            BitmapFactory.Options o2 = new BitmapFactory.Options();
            o2.inSampleSize = scale;
            try
            {
                return BitmapFactory.decodeStream(is, null, o2);
            }
            catch (Exception ex)
            {
                return loadBitmap(url, false);
            }
            finally
            {
                is.close();
                conn.disconnect();
            }
            //bitmap = BitmapFactory.decodeStream(is);

            //bitmap = BitmapFactory.decodeStream(instream);
        }
        catch (Exception e)
        {
            Log.e("grandroid", null, e);
            throw e;
        }
    }

    /**
     * @param context
     * @param uri
     * @return
     * @throws Exception
     */
    public Bitmap sampling(Context context, Uri uri) throws Exception
    {
        InputStream imageStream = context.getContentResolver().openInputStream(uri);
        BitmapFactory.Options o = new BitmapFactory.Options();
        o.inJustDecodeBounds = true;
        BitmapFactory.decodeStream(imageStream, null, o);
        imageStream.close();
        //Find the correct scale value. It should be the power of 2.

        int width_tmp = o.outWidth, height_tmp = o.outHeight;
        int scale = 1;
        while (true)
        {
            if (width_tmp <= MAX_LENGTH && height_tmp <= MAX_LENGTH)
            {
                break;
            }
            width_tmp /= 2;
            height_tmp /= 2;
            scale *= 2;
        }

        //decode with inSampleSize
        imageStream = context.getContentResolver().openInputStream(uri);
        BitmapFactory.Options o2 = new BitmapFactory.Options();
        o2.inSampleSize = scale;
        try
        {
            return BitmapFactory.decodeStream(imageStream, null, o2);
        }
        finally
        {
            imageStream.close();
        }
    }

    /**
     * @param f
     * @return
     * @throws FileNotFoundException
     */
    public Bitmap sampling(File f) throws FileNotFoundException
    {
        //InputStream instream
        //decode image size
        BitmapFactory.Options o = new BitmapFactory.Options();
        o.inJustDecodeBounds = true;
        BitmapFactory.decodeStream(new FileInputStream(f), null, o);

        //Find the correct scale value. It should be the power of 2.

        int width_tmp = o.outWidth, height_tmp = o.outHeight;
        int scale = 1;
        while (true)
        {
            if (width_tmp <= MAX_LENGTH &&
                    height_tmp <= MAX_LENGTH)
            {
                break;
            }
            width_tmp /= 2;
            height_tmp /= 2;
            scale *= 2;
        }

        //decode with inSampleSize
        BitmapFactory.Options o2 = new BitmapFactory.Options();
        final boolean isGingerBread = Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1;
        if (isGingerBread)
        {
            o2.inSampleSize = 4;
        }
        else
        {
            o2.inSampleSize = scale;
        }
        return BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
    }

    public Bitmap sampling(File f, int maxLength) throws FileNotFoundException
    {//TODO
        //InputStream instream
        //decode image size
        BitmapFactory.Options o = new BitmapFactory.Options();
        o.inJustDecodeBounds = true;
        BitmapFactory.decodeStream(new FileInputStream(f), null, o);

        //Find the correct scale value. It should be the power of 2.

        int width_tmp = o.outWidth, height_tmp = o.outHeight;
        int scale = 1;
        while (true)
        {
            if (width_tmp <= maxLength &&
                    height_tmp <= maxLength)
            {
                break;
            }
            width_tmp /= 2;
            height_tmp /= 2;
            scale *= 2;
        }

        JLog.d(JLog.JosephWang, "sampling scale " + scale);
        JLog.d(JLog.JosephWang, "sampling width_tmp " + width_tmp);
        JLog.d(JLog.JosephWang, "sampling height_tmp " + height_tmp);

        //decode with inSampleSize
        BitmapFactory.Options o2 = new BitmapFactory.Options();
        final boolean isGingerBread = Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1;
        if (isGingerBread)
        {
            o2.inSampleSize = 4;
        }
        else
        {
            o2.inSampleSize = scale;
        }
        return BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
    }

    public Bitmap scaleDown(Bitmap realImage, float maxImageSize, boolean filter)
    {
        float ratio = Math.min(
                (float) maxImageSize / realImage.getWidth(),
                (float) maxImageSize / realImage.getHeight());
        int width = Math.round((float) ratio * realImage.getWidth());
        int height = Math.round((float) ratio * realImage.getHeight());

        Bitmap newBitmap = Bitmap.createScaledBitmap(realImage, width,
                height, filter);
        return newBitmap;
    }

    /**
     * @param url
     * @param path
     * @param filename
     * @return
     * @throws Exception
     */
    public Bitmap downloadAndLoad(URL url, String path, String filename) throws Exception
    {
        /*
         * 資料夾不在就先建立
         */
        File f = new File(Environment.getExternalStorageDirectory(), path);

        if (!f.exists())
        {
            f.mkdirs();
        }
        /*
         * 儲存相片檔
         */
        File n = new File(f, filename);
        return downloadAndLoad(url, n);
    }

    /**
     * @param url
     * @param file
     * @return
     * @throws Exception
     */
    public Bitmap downloadAndLoad(URL url, File file) throws Exception
    {

        Bitmap bmp = sampling(url);
        if (bmp != null)
        {
            saveBitmap(bmp, file, !url.getPath().endsWith("png"), 100);
            return bmp;
        }
        else
        {
            /*
             * Open a connection to that URL.
             */
            URLConnection ucon = url.openConnection();
            ucon.setConnectTimeout(10000);

            /*
             * Define InputStreams to read from the URLConnection.
             */
            InputStream is = ucon.getInputStream();
            BufferedInputStream bis = new BufferedInputStream(is);

            /*
             * Read bytes to the Buffer until there is nothing more to read(-1).
             */
            ByteArrayBuffer baf = new ByteArrayBuffer(50);
            int current = 0;
            while ((current = bis.read()) != -1)
            {
                baf.append((byte) current);
            }

            /*
             * Convert the Bytes read to a String.
             */
            FileOutputStream fos = new FileOutputStream(file);
            byte[] imageByteArray = baf.toByteArray();
            fos.write(imageByteArray);
            fos.close();
            return BitmapFactory.decodeByteArray(imageByteArray, 0, imageByteArray.length);
        }

    }

    /**
     * @param bitmap
     * @param path
     * @return
     */
    public static String saveBitmap(Bitmap bitmap, String path)
    {
        long cnt = System.currentTimeMillis();
        return saveBitmap(bitmap, path, cnt + ".jpg", true, 100);
    }

    /**
     * @param bitmap
     * @param path
     * @param fileNamePrefix
     * @param fileNameSuffix
     * @param saveAsJPEG
     * @param quality
     * @return
     */
    public static String saveBitmap(Bitmap bitmap, String path, String fileNamePrefix, String fileNameSuffix, boolean saveAsJPEG, int quality)
    {
        if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()))
        {
            try
            {
                /*
                 * 資料夾不在就先建立
                 */
                File f = new File(Environment.getExternalStorageDirectory(), path);
                if (!f.exists())
                {
                    f.mkdir();
                }
                NumberFormat nf = new DecimalFormat("0000");
                for (int fileIndex = 1; fileIndex <= 9999; fileIndex++)
                {
                    String fileName = fileNamePrefix + nf.format(fileIndex) + fileNameSuffix;
                    File n = new File(f, fileName);
                    if (!n.exists())
                    {
                        return saveBitmap(bitmap, path, fileName, saveAsJPEG, quality);
                    }
                }
            }
            catch (Exception e)
            {
                Log.e("grandroid", null, e);
            }
        }
        return null;
    }

    /**
     * @param bitmap
     * @param path
     * @param fileName
     * @param saveAsJPEG
     * @param quality
     * @return
     */
    public static String saveBitmap(Bitmap bitmap, String path, String fileName, boolean saveAsJPEG, int quality)
    {
        /*
         * 儲存檔案
         */
        if (bitmap != null)
        {
            /*
             * 檢視SDCard是否存在
             */
            if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()))
            {
                /*
                 * SD卡不存在,顯示Toast訊息
                 */
            }
            else
            {
                try
                {
                    /*
                     * 資料夾不在就先建立
                     */
                    File f = new File(
                            Environment.getExternalStorageDirectory(), path);

                    if (!f.exists())
                    {
                        f.mkdir();
                    }

                    /*
                     * 儲存相片檔
                     */
                    File n = new File(f, fileName);
                    FileOutputStream bos =
                            new FileOutputStream(n.getAbsolutePath());
                    /*
                     * 檔案轉換
                     */
                    if (saveAsJPEG)
                    {
                        bitmap.compress(Bitmap.CompressFormat.JPEG, quality, bos);
                    }
                    else
                    {
                        bitmap.compress(Bitmap.CompressFormat.PNG, quality, bos);
                    }
                    /*
                     * 呼叫flush()方法,更新BufferStream
                     */
                    bos.flush();
                    /*
                     * 結束OutputStream
                     */
                    bos.close();
                    return n.getAbsolutePath();
                }
                catch (Exception e)
                {
                    Log.e("grandroid", null, e);
                }
            }
        }
        return null;
    }

    public static String saveBitmap(Bitmap bitmap, File file, boolean saveAsJPEG, int quality) throws Exception
    {
        /*
         * 儲存檔案
         */
        if (bitmap != null)
        {
            /*
             * 檢視SDCard是否存在
             */
            if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()))
            {
                /*
                 * SD卡不存在,顯示Toast訊息
                 */
            }
            else
            {
                FileOutputStream bos =
                        new FileOutputStream(file.getAbsolutePath());
                /*
                 * 檔案轉換
                 */
                if (saveAsJPEG)
                {
                    bitmap.compress(Bitmap.CompressFormat.JPEG, quality, bos);
                }
                else
                {
                    bitmap.compress(Bitmap.CompressFormat.PNG, quality, bos);
                }
                /*
                 * 呼叫flush()方法,更新BufferStream
                 */
                bos.flush();
                /*
                 * 結束OutputStream
                 */
                bos.close();
                return file.getAbsolutePath();
            }
        }
        return null;
    }

    /**
     * @param bitmap
     * @param scale
     * @return
     */
    public Bitmap resizeBitmap(Bitmap bitmap, float scale)
    {
        return resizeBitmap(bitmap, scale, false);
    }

    public Bitmap resizeBitmap(Bitmap bitmap, float scale, boolean recycleOldBitmap)
    {
        Matrix matrix = new Matrix();
        // resize the Bitmap
        matrix.postScale(scale, scale);
        if (recycleOldBitmap)
        {
            int w = (int) (scale * bitmap.getWidth());
            int h = (int) (scale * bitmap.getHeight());
            Bitmap newBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
            Canvas c = new Canvas(newBitmap);
            c.drawBitmap(bitmap, matrix, new Paint());
            return newBitmap;
        }
        else
        {
            Bitmap newBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
            return newBitmap;
        }
    }

    public Bitmap rotateBitmap(Bitmap bitmap, int angle)
    {
        return rotateBitmap(bitmap, angle, false);
    }

    public Bitmap rotateBitmap(Bitmap bitmap, int angle, boolean recycleOldBitmap)
    {
        Matrix mtx = new Matrix();
        mtx.postRotate(angle);
        try
        {
            return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), mtx, false);
        }
        finally
        {
            if (recycleOldBitmap)
            {
                bitmap.recycle();
            }
        }
    }

    public Bitmap resizeBitmapMaxWidth(Bitmap bitmap, int width, boolean recycleOldBitmap)
    {
        if (bitmap.getWidth() > width)
        {
            return resizeBitmap(bitmap, width / (float) bitmap.getWidth(), recycleOldBitmap);
        }
        else
        {
            return bitmap;
        }
    }

    public Bitmap resizeBitmapFitWidth(Bitmap bitmap, int width, boolean recycleOldBitmap)
    {
        return resizeBitmap(bitmap, width / (float) bitmap.getWidth(), recycleOldBitmap);
    }

    /**
     * @param bitmap
     * @param width
     * @return
     */
    public Bitmap resizeBitmapMaxWidth(Bitmap bitmap, int width)
    {
        if (bitmap.getWidth() > width)
        {
            return resizeBitmap(bitmap, width / (float) bitmap.getWidth());
        }
        else
        {
            return bitmap;
        }
    }

    public Bitmap resizeBitmapMaxHeight(Bitmap bitmap, int height, boolean recycleOldBitmap)
    {
        if (bitmap.getHeight() > height)
        {
            return resizeBitmap(bitmap, height / (float) bitmap.getHeight(), recycleOldBitmap);
        }
        else
        {
            return bitmap;
        }
    }

    public Bitmap resizeBitmapFitHeight(Bitmap bitmap, int height, boolean recycleOldBitmap)
    {
        return resizeBitmap(bitmap, height / (float) bitmap.getHeight(), recycleOldBitmap);
    }

    /**
     * @param bitmap
     * @param height
     * @return
     */
    public Bitmap resizeBitmapMaxHeight(Bitmap bitmap, int height)
    {
        if (bitmap.getHeight() > height)
        {
            return resizeBitmap(bitmap, height / (float) bitmap.getHeight());
        }
        else
        {
            return bitmap;
        }
    }

    /**
     * @param bmp1
     * @param bmp2
     * @param left
     * @param top
     * @return
     */
    public Bitmap overlay(Bitmap bmp1, Bitmap bmp2, float left, float top)
    {
        Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig());
        Canvas canvas = new Canvas(bmOverlay);
        canvas.drawBitmap(bmp1, new Matrix(), null);
        canvas.drawBitmap(bmp2, left, top, null);
        return bmOverlay;
    }

    /**
     * @param bmp
     * @return
     */
    public Bitmap cut(Bitmap bmp)
    {
        return cut(bmp, false);
    }

    public Bitmap cut(Bitmap bmp, boolean recycleOldBitmap)
    {
        int w = bmp.getWidth();
        int h = bmp.getHeight();
        if (w > h)
        {
            return cut(bmp, (w - h) / 2f, 0, recycleOldBitmap);
        }
        else if (h > w)
        {
            return cut(bmp, 0, (h - w) / 2f, recycleOldBitmap);
        }
        else
        {
            return bmp;
        }
    }

    /**
     * @param bmp
     * @param cutMarginX
     * @param cutMarginY
     * @return
     */
    public Bitmap cut(Bitmap bmp, float cutMarginX, float cutMarginY)
    {
        return cut(bmp, cutMarginX, cutMarginY, false);
    }

    public Bitmap cut(Bitmap bmp, float cutMarginX, float cutMarginY, boolean recycleOldBitmap)
    {
        Bitmap bmOverlay = Bitmap.createBitmap(bmp.getWidth() - Math.round(2 * cutMarginX), bmp.getHeight() - Math.round(2 * cutMarginY), bmp.getConfig());
        Canvas canvas = new Canvas(bmOverlay);
        canvas.drawBitmap(bmp, -cutMarginX, -cutMarginY, null);
        if (recycleOldBitmap)
        {
            bmp.recycle();
        }
        Log.d("grandroid", "after cut, bitmap is recycled? " + bmOverlay.isRecycled());
        return bmOverlay;
    }

    /**
     * @param bmp
     * @param cutLeft
     * @param cutTop
     * @param cutRight
     * @param cutBottom
     * @return
     */
    public Bitmap cut(Bitmap bmp, int cutLeft, int cutTop, int cutRight, int cutBottom)
    {
        return cut(bmp, cutLeft, cutTop, cutRight, cutBottom, false);
    }

    public static Bitmap cut(Bitmap bmp, int cutLeft, int cutTop, int cutRight, int cutBottom, boolean recycleOldBitmap)
    {
        Bitmap bmOverlay = Bitmap.createBitmap(bmp.getWidth() - (cutLeft + cutRight), bmp.getHeight() - (cutTop + cutBottom), bmp.getConfig());
        Canvas canvas = new Canvas(bmOverlay);
        canvas.drawBitmap(bmp, -cutLeft, -cutTop, null);
        bmp.recycle();
        return bmOverlay;
    }

    /**
     * @param bitmap
     * @param edge
     * @return
     */
    public Bitmap square(Bitmap bitmap, float edge)
    {
        return square(bitmap, edge, false);
    }

    public Bitmap square(Bitmap bitmap, float edge, boolean recycleOldBitmap)
    {
        Matrix matrix = new Matrix();
        // resize the Bitmap
        try
        {
            if (bitmap.getWidth() > bitmap.getHeight())
            {
                matrix.postScale(edge / bitmap.getHeight(), edge / bitmap.getHeight());
                return Bitmap.createBitmap(bitmap, (bitmap.getWidth() - bitmap.getHeight()) / 2, 0, bitmap.getHeight(), bitmap.getHeight(), matrix, true);
            }
            else
            {
                matrix.postScale(edge / bitmap.getWidth(), edge / bitmap.getWidth());
                return Bitmap.createBitmap(bitmap, 0, (bitmap.getHeight() - bitmap.getWidth()) / 2, bitmap.getWidth(), bitmap.getWidth(), matrix, true);
            }
        }
        finally
        {
            if (recycleOldBitmap)
            {
                bitmap.recycle();
            }
        }
    }

    public Bitmap round(Bitmap bitmap)
    {
        return round(bitmap, 12);
    }

    public Bitmap round(Bitmap bitmap, int roundPx)
    {
        return round(bitmap, bitmap.getWidth(), roundPx);
    }

    public Bitmap round(Bitmap bitmap, int edge, int roundPx)
    {
        Bitmap output = Bitmap.createBitmap(edge, edge, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(output);

        int color = 0xff424242;
        Paint paint = new Paint();
        Rect rect = new Rect(0, 0, edge, edge);
        RectF rectF = new RectF(rect);

        paint.setAntiAlias(true);
        canvas.drawARGB(0, 0, 0, 0);
        paint.setColor(color);

        canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
        if (edge != bitmap.getWidth())
        {
            int minLength = Math.min(bitmap.getWidth(), bitmap.getHeight());
            Matrix m = new Matrix();
            if (bitmap.getWidth() > bitmap.getHeight())
            {
                m.setTranslate(-(bitmap.getWidth() - minLength) / 2, 0);
            }
            else
            {
                m.setTranslate(0, -(bitmap.getHeight() - minLength) / 2);
            }
            m.setScale(edge / (float) minLength, edge / (float) minLength);
            canvas.drawBitmap(bitmap, m, paint);
        }
        else
        {
            canvas.drawBitmap(bitmap, rect, rect, paint);
        }
        bitmap.recycle();
        return output;
    }

    public Bitmap circle(Bitmap bitmapimg)
    {
        int length = Math.min(bitmapimg.getWidth(), bitmapimg.getHeight());
        Bitmap output = Bitmap.createBitmap(length,
                length, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(output);

        final int color = 0xff424242;
        final Paint paint = new Paint();
        final Rect rect = new Rect(0, 0, length,
                length);

        paint.setAntiAlias(true);
        canvas.drawARGB(0, 0, 0, 0);
        paint.setColor(color);
        canvas.drawCircle(length / 2,
                length / 2, length / 2, paint);
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
        canvas.drawBitmap(bitmapimg, rect, rect, paint);
        bitmapimg.recycle();
        return output;
    }

    public static byte[] toBytes(Bitmap bmp)
    {
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        bmp.compress(Bitmap.CompressFormat.JPEG, 90, stream);
        return stream.toByteArray();
    }

    public static String toPngBase64String(Bitmap bmp)
    {
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
        return Base64.encodeToString(stream.toByteArray(), Base64.NO_WRAP);
    }

    public Bitmap toGrayscale(Bitmap bmp)
    {
        return toGrayscale(bmp, false);
    }

    public Bitmap getScaleBitMap(int deviceWidth, Bitmap origin)
    {
        int height = deviceWidth * origin.getHeight() / origin.getWidth();
        Bitmap bitmap = Bitmap.createScaledBitmap(origin, deviceWidth, height, true);
        return bitmap;
    }

    public Bitmap toGrayscale(Bitmap bmp, boolean recycleOldBitmap)
    {
        Bitmap bmpGrayscale = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), Bitmap.Config.ARGB_8888);
        Canvas c = new Canvas(bmpGrayscale);
        Paint paint = new Paint();
        ColorMatrix cm = new ColorMatrix();
        cm.setSaturation(0);
        ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);
        paint.setColorFilter(f);
        c.drawBitmap(bmp, 0, 0, paint);
        if (recycleOldBitmap)
        {
            bmp.recycle();
        }
        return bmpGrayscale;
    }

    public static byte[] drawableToByte(Drawable d)
    {
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        if (d instanceof BitmapDrawable)
        {
            Bitmap bitmap = ((BitmapDrawable) d).getBitmap();
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
            return stream.toByteArray();
        }
        else
        {
            return new byte[]{};
        }
    }

    @SuppressWarnings("deprecation")
    public Drawable decodeImage(InputStream inputStream)
    {
        byte[] byteArr = new byte[0];
        byte[] buffer = new byte[1024];
        int len;
        int count = 0;
        try
        {
            while ((len = inputStream.read(buffer)) > -1)
            {
                if (len != 0)
                {
                    if (count + len > byteArr.length)
                    {
                        byte[] newbuf = new byte[(count + len) * 2];
                        System.arraycopy(byteArr, 0, newbuf, 0, count);
                        byteArr = newbuf;
                    }
                    System.arraycopy(buffer, 0, byteArr, count, len);
                    count += len;
                }
            }
            return new BitmapDrawable(BitmapFactory.decodeByteArray(byteArr, 0, count));
        }
        catch (Exception e)
        {
            e.printStackTrace();
            return null;
        }
    }

    @SuppressWarnings("deprecation")
    public Drawable decodeImage(InputStream inputStream, int reqWidth, int reqHeight)
    {
        byte[] byteArr = new byte[0];
        byte[] buffer = new byte[1024];
        int len;
        int count = 0;
        try
        {
            while ((len = inputStream.read(buffer)) > -1)
            {
                if (len != 0)
                {
                    if (count + len > byteArr.length)
                    {
                        byte[] newbuf = new byte[(count + len) * 2];
                        System.arraycopy(byteArr, 0, newbuf, 0, count);
                        byteArr = newbuf;
                    }
                    System.arraycopy(buffer, 0, byteArr, count, len);
                    count += len;
                }
            }
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inJustDecodeBounds = true;
            BitmapFactory.decodeByteArray(byteArr, 0, count, options);
            options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
            options.inPurgeable = true;
            options.inInputShareable = true;
            options.inJustDecodeBounds = false;
            options.inPreferredConfig = Bitmap.Config.ARGB_8888;
            JLog.d(JLog.JosephWang, "decodeImage byteArr.length " + byteArr.length);
            return new BitmapDrawable(BitmapFactory.decodeByteArray(byteArr, 0, count, options));
        }
        catch (Exception e)
        {
            e.printStackTrace();
            return null;
        }
    }

    public Bitmap drawableToBitmap(Drawable drawable)
    {
        if (drawable instanceof BitmapDrawable)
        {
            return ((BitmapDrawable) drawable).getBitmap();
        }
        if (drawable.getIntrinsicWidth() > 0 && drawable.getIntrinsicHeight() > 0)
        {
            Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(bitmap);
            drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
            drawable.draw(canvas);
            return bitmap;
        }
        else
        {
            return null;
        }
    }

    public static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight)
    {
        // Raw height and width of image
        final int height = options.outHeight;
        final int width = options.outWidth;
        int inSampleSize = 1;

        if (height > reqHeight || width > reqWidth)
        {

            // Calculate ratios of height and width to requested height and
            // width
            final int heightRatio = Math.round((float) height / (float) reqHeight);
            final int widthRatio = Math.round((float) width / (float) reqWidth);

            // Choose the smallest ratio as inSampleSize value, this will
            // guarantee
            // a final image with both dimensions larger than or equal to the
            // requested height and width.
            inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio;
        }

        return inSampleSize;
    }

    public static interface SavePhotoListener
    {
        public void savePhotoEvent(boolean successful);
    }

    public static void storeJpegInSdCard(final JActivity act, final String fileName, final byte[] imageData, final int contentLength, final SavePhotoListener listener)
    {
        act.runOnUiThread(new Runnable()
        {
            @Override
            public void run()
            {
                synchronized (imageData)
                {
                    boolean isSuccessful = true;
                    try
                    {
                        String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getPath();
                        JLog.d(JLog.JosephWang, " storeJpegInApp path " + path);
                        File file = new File(path, fileName + ".jpg");
                        OutputStream fOut = new FileOutputStream(file);
                        fOut.write(imageData);
                        fOut.flush();
                        fOut.close();
                        ContentValues values = new ContentValues();
                        values.put(MediaStore.Images.Media.DISPLAY_NAME, fileName);
                        values.put(MediaStore.Images.Media.DESCRIPTION, fileName);
                        values.put(MediaStore.MediaColumns.DATE_ADDED, fileName);
                        values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpg");
                        values.put(MediaStore.Images.Media.SIZE, imageData.length);
                        values.put(MediaStore.Images.Media.DATA, file.getAbsolutePath());
                        act.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
                        isSuccessful = true;
                    }
                    catch (FileNotFoundException e)
                    {
                        e.printStackTrace();
                        isSuccessful = false;
                    }
                    catch (IOException e)
                    {
                        e.printStackTrace();
                        isSuccessful = false;
                    }
                    finally
                    {
                        if (act != null && listener != null && isSuccessful)
                        {
                            listener.savePhotoEvent(true);
                        }
                        else
                        {
                            listener.savePhotoEvent(false);
                        }
                    }
                }
            }
        });
    }

//    public static void savePhotoToAlbum(String imageFilePath)
//    {
//        savePhotoToAlbum(BaseApplication.getContext(), imageFilePath);
//    }
//
//    public static void savePhotoToAlbum(Context ctx, String imageFilePath)
//    {
//        MediaScannerConnection.scanFile(ctx, new String[]{imageFilePath},
//                new String[]{"image/jpeg"}, null);
//    }

    public static String saveImageToGalleryReturnPath(Bitmap photo, String title, String description)
    {
        return saveImageToGalleryReturnPath(BaseApplication.getContext(), photo, title, description);
    }

    public static String saveImageToGalleryReturnPath(Context ctx, Bitmap photo, String title, String description)
    {
        String path = MediaStore.Images.Media.insertImage(ctx.getContentResolver(), photo, title, description);
        return path;
    }

    public static void replaceColorInBitmap(Bitmap resource, int color)
    {
        int width = resource.getWidth();
        int height = resource.getHeight();
        int[] allpixels = new int[width * height];

        resource.getPixels(allpixels, 0, width, 0, 0, width, height);

        for (int i = 0; i < allpixels.length; i++)
        {
            if (allpixels[i] == Color.WHITE)
            {
                allpixels[i] = color ;
            }
        }
        resource.setPixels(allpixels, 0, width, 0, 0, width, height);
    }

    public static void changeBitmapColor(Bitmap sourceBitmap, ImageView image, int color)
    {
        Bitmap resultBitmap = Bitmap.createBitmap(sourceBitmap, 0, 0,
                sourceBitmap.getWidth() - 1, sourceBitmap.getHeight() - 1);
        Paint p = new Paint();
        ColorFilter filter = new LightingColorFilter(color, 1);
        p.setColorFilter(filter);
        image.setImageBitmap(resultBitmap);

        Canvas canvas = new Canvas(resultBitmap);
        canvas.drawBitmap(resultBitmap, 0, 0, p);
    }

    public static void recycleBitmap(Bitmap map)
    {
        if (map != null && !map.isRecycled())
        {
            map.recycle();
        }
    }

    public static Bitmap replaceColorInBitmap(Bitmap myBitmap, int targetColor, int replaceColor)
    {
        int width = myBitmap.getWidth();
        int height = myBitmap.getHeight();
        int[] allpixels = new int[width * height];

        Bitmap resultBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        myBitmap.getPixels(allpixels, 0, width, 0, 0, width, height);

        for (int i = 0; i < allpixels.length; i++)
        {
            if (allpixels[i] == targetColor)
            {
                allpixels[i] = replaceColor;
            }
        }
        resultBitmap.setPixels(allpixels, 0, width, 0, 0, width, height);
        return resultBitmap;
    }
}


text:
'use strict';
// Descend into a directory structure and, for each file matching *.node, output
// based on the imports found in the file whether it's an N-API module or not.

const fs = require('fs');
const path = require('path');
const child_process = require('child_process');

// Read the output of the command, break it into lines, and use the reducer to
// decide whether the file is an N-API module or not.
function checkFile(file, command, argv, reducer) {
  const child = child_process.spawn(command, argv, {
    stdio: ['inherit', 'pipe', 'inherit']
  });
  let leftover = '';
  let isNapi = undefined;
  child.stdout.on('data', (chunk) => {
    if (isNapi === undefined) {
      chunk = (leftover + chunk.toString()).split(/[\r\n]+/);
      leftover = chunk.pop();
      isNapi = chunk.reduce(reducer, isNapi);
      if (isNapi !== undefined) {
        child.kill();
      }
    }
  });
  child.on('close', (code, signal) => {
    if ((code === null && signal !== null) || (code !== 0)) {
      console.log(
        command + ' exited with code: '  + code + ' and signal: ' + signal);
    } else {
      // Green if it's a N-API module, red otherwise.
      console.log(
          '\x1b[' + (isNapi ? '42' : '41') + 'm' +
          (isNapi ? '    N-API' : 'Not N-API') +
          '\x1b[0m: ' + file);
    }
  });
}

// Use nm -a to list symbols.
function checkFileUNIX(file) {
  checkFile(file, 'nm', ['-a', file], (soFar, line) => {
    if (soFar === undefined) {
      line = line.match(/([0-9a-f]*)? ([a-zA-Z]) (.*$)/);
      if (line[2] === 'U') {
        if (/^napi/.test(line[3])) {
          soFar = true;
        }
      }
    }
    return soFar;
  });
}

// Use dumpbin /imports to list symbols.
function checkFileWin32(file) {
  checkFile(file, 'dumpbin', ['/imports', file], (soFar, line) => {
    if (soFar === undefined) {
      line = line.match(/([0-9a-f]*)? +([a-zA-Z0-9]) (.*$)/);
      if (line && /^napi/.test(line[line.length - 1])) {
        soFar = true;
      }
    }
    return soFar;
  });
}

// Descend into a directory structure and pass each file ending in '.node' to
// one of the above checks, depending on the OS.
function recurse(top) {
  fs.readdir(top, (error, items) => {
    if (error) {
      throw ("error reading directory " + top + ": " + error);
    }
    items.forEach((item) => {
      item = path.join(top, item);
      fs.stat(item, ((item) => (error, stats) => {
        if (error) {
          throw ("error about " + item + ": " + error);
        }
        if (stats.isDirectory()) {
          recurse(item);
        } else if (/[.]node$/.test(item) &&
            // Explicitly ignore files called 'nothing.node' because they are
            // artefacts of node-addon-api having identified a version of
            // Node.js that ships with a correct implementation of N-API.
            path.basename(item) !== 'nothing.node') {
          process.platform === 'win32' ?
              checkFileWin32(item) :
              checkFileUNIX(item);
        }
      })(item));
    });
  });
}

// Start with the directory given on the command line or the current directory
// if nothing was given.
recurse(process.argv.length > 3 ? process.argv[2] : '.');


text:
package org.spongepowered.mod.mixin.core.event.state;

import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLStateEvent;
import org.spongepowered.api.event.state.PostInitializationEvent;
import org.spongepowered.api.util.annotation.NonnullByDefault;
import org.spongepowered.asm.mixin.Mixin;

@NonnullByDefault
@Mixin(FMLPostInitializationEvent.class)
public abstract class MixinEventPostInit extends FMLStateEvent implements PostInitializationEvent {
}


text:
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Runtime.CompilerServices;

namespace System.Text.Primitives
{
    internal static class Utf8Helper
    {
        #region Constants
        // To get this to compile with dotnet cli, we need to temporarily un-binary the magic values
        private const byte b0000_0111U = 0x07; //7
        private const byte b0000_1111U = 0x0F; //15
        private const byte b0001_1111U = 0x1F; //31
        private const byte b0011_1111U = 0x3F; //63
        private const byte b0111_1111U = 0x7F; //127
        private const byte b1000_0000U = 0x80; //128
        private const byte b1100_0000U = 0xC0; //192
        private const byte b1110_0000U = 0xE0; //224
        private const byte b1111_0000U = 0xF0; //240
        private const byte b1111_1000U = 0xF8; //248

        private const byte NonFirstByteInCodePointValue = 0x80;
        private const byte NonFirstByteInCodePointMask = 0xC0;

        public const int MaxCodeUnitsPerCodePoint = 4;

        #endregion Constants

        public static bool TryDecodeCodePoint(ReadOnlySpan<byte> utf8, int index, out uint codePoint, out int bytesConsumed)
        {
            if (index >= utf8.Length)
            {
                codePoint = default;
                bytesConsumed = 0;
                return false;
            }

            var first = utf8[index];

            bytesConsumed = GetEncodedBytes(first);
            if (bytesConsumed == 0 || utf8.Length - index < bytesConsumed)
            {
                bytesConsumed = 0;
                codePoint = default;
                return false;
            }

            switch (bytesConsumed)
            {
                case 1:
                    codePoint = first;
                    break;

                case 2:
                    codePoint = (uint)(first & b0001_1111U);
                    break;

                case 3:
                    codePoint = (uint)(first & b0000_1111U);
                    break;

                case 4:
                    codePoint = (uint)(first & b0000_0111U);
                    break;

                default:
                    codePoint = default;
                    bytesConsumed = 0;
                    return false;
            }

            for (var i = 1; i < bytesConsumed; i++)
            {
                uint current = utf8[index + i];
                if ((current & b1100_0000U) != b1000_0000U)
                {
                    bytesConsumed = 0;
                    codePoint = default;
                    return false;
                }

                codePoint = (codePoint << 6) | (b0011_1111U & current);
            }

            return true;
        }

        private static int GetEncodedBytes(byte b)
        {
            if ((b & b1000_0000U) == 0)
                return 1;

            if ((b & b1110_0000U) == b1100_0000U)
                return 2;

            if ((b & b1111_0000U) == b1110_0000U)
                return 3;

            if ((b & b1111_1000U) == b1111_0000U)
                return 4;

            return 0;
        }

        public static int GetNumberOfEncodedBytes(uint codePoint)
        {
            if (codePoint <= 0x7F)
                return 1;

            if (codePoint <= 0x7FF)
                return 2;

            if (codePoint <= 0xFFFF)
                return 3;

            if (codePoint <= 0x10FFFF)
                return 4;

            return 0;
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        private static bool IsFirstCodeUnitInEncodedCodePoint(byte codeUnit)
        {
            return (codeUnit & NonFirstByteInCodePointMask) != NonFirstByteInCodePointValue;
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        private static bool TryFindEncodedCodePointBytesCountGoingBackwards(ReadOnlySpan<byte> buffer, out int encodedBytes)
        {
            encodedBytes = 1;
            ReadOnlySpan<byte> it = buffer;
            // TODO: Should we have something like: Span<byte>.(Slice from the back)
            for (; encodedBytes <= MaxCodeUnitsPerCodePoint; encodedBytes++, it = it.Slice(0, it.Length - 1))
            {
                if (it.Length == 0)
                {
                    encodedBytes = default;
                    return false;
                }

                // TODO: Should we have Span<byte>.Last?
                if (IsFirstCodeUnitInEncodedCodePoint(it[it.Length - 1]))
                {
                    // output: encodedBytes
                    return true;
                }
            }

            // Invalid unicode character or stream prematurely ended (which is still invalid character in that stream)
            encodedBytes = default;
            return false;
        }

        // TODO: Name TBD
        // TODO: optimize?
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static bool TryDecodeCodePointBackwards(ReadOnlySpan<byte> buffer, out uint codePoint, out int encodedBytes)
        {
            if (TryFindEncodedCodePointBytesCountGoingBackwards(buffer, out encodedBytes))
            {
                // TODO: Inline decoding, as the invalid surrogate check can be done faster
                bool ret = TryDecodeCodePoint(buffer, buffer.Length - encodedBytes, out codePoint, out int realEncodedBytes);
                if (ret && encodedBytes != realEncodedBytes)
                {
                    // invalid surrogate character
                    // we know the character length by iterating on surrogate characters from the end
                    // but the first byte of the character has also encoded length
                    // seems like the lengths don't match
                    codePoint = default;
                    return false;
                }

                return true;
            }

            codePoint = default;
            encodedBytes = default;
            return false;
        }

        // TODO: Should we rewrite this to not use char.ConvertToUtf32 or is it fast enough?
        public static bool TryDecodeCodePointFromString(string s, int index, out uint codePoint, out int encodedChars)
        {
            if (index < 0 || index >= s.Length)
            {
                codePoint = default;
                encodedChars = 0;
                return false;
            }

            if (index == s.Length - 1 && char.IsSurrogate(s[index]))
            {
                codePoint = default;
                encodedChars = 0;
                return false;
            }

            encodedChars = char.IsHighSurrogate(s[index]) ? 2 : 1;
            codePoint = unchecked((uint)char.ConvertToUtf32(s, index));

            return true;
        }
    }
}


text:
/*
Package gocal implements a PDF calendar generator. It consists of a
library gocal and a standalone tool gocalendar.

* Inspired by pcal

* Simplicity: Create a nice calendar with minimum effort.

* Week number

* Moonphase

* Add events from configuration file

* Set papersize

* Choose fonts (limited)

* Several languages

* Day of year

* Background image

* Photo calendar

* More

For build instructions, test instructions, examples, see
README.md.

EXAMPLE

	package main
	import (
		"github.com/StefanSchroeder/Gocal"
	)
	func main() {
		g := gocal.New(1,12,2010)
		g.CreateCalendar("test-example01.pdf")
	}

*/
package gocal


text:
package net.opengis.gml.impl;
/**
 * A document containing one baseCRS(@http://www.opengis.net/gml) element.
 *
 * This is a complex type.
 */
public class BaseCRSDocumentImpl extends org.apache.xmlbeans.impl.values.XmlComplexContentImpl implements net.opengis.gml.BaseCRSDocument
{
    private static final long serialVersionUID = 1L;

    public BaseCRSDocumentImpl(org.apache.xmlbeans.SchemaType sType)
    {
        super(sType);
    }

    private static final javax.xml.namespace.QName BASECRS$0 =
        new javax.xml.namespace.QName("http://www.opengis.net/gml", "baseCRS");

    /**
     * Gets the "baseCRS" element
     */
    public net.opengis.gml.CoordinateReferenceSystemRefType getBaseCRS()
    {
        synchronized (monitor())
        {
            check_orphaned();
            net.opengis.gml.CoordinateReferenceSystemRefType target = null;
            target = (net.opengis.gml.CoordinateReferenceSystemRefType)get_store().find_element_user(BASECRS$0, 0);
            if (target == null)
            {
                return null;
            }
            return target;
        }
    }

    /**
     * Sets the "baseCRS" element
     */
     public void setBaseCRS(net.opengis.gml.CoordinateReferenceSystemRefType baseCRS)
    {
        generatedSetterHelperImpl(baseCRS, BASECRS$0, 0, org.apache.xmlbeans.impl.values.XmlObjectBase.KIND_SETTERHELPER_SINGLETON);
    }

    /**
     * Appends and returns a new empty "baseCRS" element
     */
    public net.opengis.gml.CoordinateReferenceSystemRefType addNewBaseCRS()
    {
        synchronized (monitor())
        {
            check_orphaned();
            net.opengis.gml.CoordinateReferenceSystemRefType target = null;
            target = (net.opengis.gml.CoordinateReferenceSystemRefType)get_store().add_element_user(BASECRS$0);
            return target;
        }
    }
}


text:
{-# LANGUAGE MultiParamTypeClasses #-}
{-# OPTIONS_HADDOCK hide #-}
-----------------------------------------------------------------------------
-- |
-- Module     : Data.Matrix.Class.MSolveBase
-- Copyright  : Copyright (c) , Patrick Perry <patperry@stanford.edu>
-- License    : BSD3
-- Maintainer : Patrick Perry <patperry@stanford.edu>
-- Stability  : experimental
--
-- An overloaded interface for solving matrix systems in a monad.  The
-- matrices can operate via inverse multiplication on immutable dense
-- vectors and matrices.
--

module Data.Matrix.Class.MSolveBase (
    -- * The MSolve type class
    MSolve(..),

    -- * Solving linear systems
    getSolveVector,
    getSolveMatrix,
    getSSolveVector,
    getSSolveMatrix,

    -- * In-place operations
    doSolveVector,
    doSolveMatrix,
    doSSolveVector,
    doSSolveMatrix,
    doSolveVector_,
    doSolveMatrix_,
    doSSolveVector_,
    doSSolveMatrix_,

    -- * Unsafe operations
    unsafeGetSolveVector,
    unsafeGetSolveMatrix,
    unsafeGetSSolveVector,
    unsafeGetSSolveMatrix,

    ) where

import BLAS.Internal ( checkMatVecSolv, checkMatMatSolv, checkMatVecSolvTo,
    checkMatMatSolvTo, checkSquare )

import Data.Elem.BLAS
import Data.Matrix.Class
import Data.Tensor.Class
import Data.Vector.Dense.Class
import Data.Matrix.Dense.Base

unsafeGetSolveVector :: (MSolve a m, ReadVector y m, WriteVector x m, BLAS2 e) =>
    a e -> y e -> m (x e)
unsafeGetSolveVector a y = do
    x  <- newVector_ (numCols a)
    unsafeDoSolveVector a y x
    return x
{-# INLINE unsafeGetSolveVector #-}

unsafeGetSSolveVector :: (MSolve a m, ReadVector y m, WriteVector x m, BLAS2 e) =>
    e -> a e -> y e -> m (x e)
unsafeGetSSolveVector alpha a y = do
    x  <- newVector_ (numCols a)
    unsafeDoSSolveVector alpha a y x
    return x
{-# INLINE unsafeGetSSolveVector #-}

unsafeGetSolveMatrix :: (MSolve a m, ReadMatrix c m, WriteMatrix b m, BLAS3 e) =>
    a e -> c e -> m (b e)
unsafeGetSolveMatrix a c = do
    b  <- newMatrix_ (numCols a, numCols c)
    unsafeDoSolveMatrix a c b
    return b
{-# INLINE unsafeGetSolveMatrix #-}

unsafeGetSSolveMatrix :: (MSolve a m, ReadMatrix c m, WriteMatrix b m, BLAS3 e) =>
    e -> a e -> c e -> m (b e)
unsafeGetSSolveMatrix alpha a c = do
    b  <- newMatrix_ (numCols a, numCols c)
    unsafeDoSSolveMatrix alpha a c b
    return b
{-# INLINE unsafeGetSSolveMatrix #-}

-- | Return @x@ such that @a x = y@.
getSolveVector :: (MSolve a m, ReadVector y m, WriteVector x m, BLAS2 e) =>
    a e -> y e -> m (x e)
getSolveVector a y =
    checkMatVecSolv (shape a) (dim y) $
        unsafeGetSolveVector a y
{-# INLINE getSolveVector #-}

-- | Return @x@ such that @a x = alpha y@.
getSSolveVector :: (MSolve a m, ReadVector y m, WriteVector x m, BLAS2 e) =>
    e -> a e -> y e -> m (x e)
getSSolveVector alpha a y =
    checkMatVecSolv (shape a) (dim y) $
        unsafeGetSSolveVector alpha a y
{-# INLINE getSSolveVector #-}

-- | Return @b@ such that @a b = c@.
getSolveMatrix :: (MSolve a m, ReadMatrix c m, WriteMatrix b m, BLAS3 e) =>
    a e -> c e -> m (b e)
getSolveMatrix a c =
    checkMatMatSolv (shape a) (shape c) $
            unsafeGetSolveMatrix a c
{-# INLINE getSolveMatrix #-}

-- | Return @b@ such that @a b = alpha c@.
getSSolveMatrix :: (MSolve a m, ReadMatrix c m, WriteMatrix b m, BLAS3 e) =>
    e -> a e -> c e -> m (b e)
getSSolveMatrix alpha a b =
    checkMatMatSolv (shape a) (shape b) $
            unsafeGetSSolveMatrix alpha a b
{-# INLINE getSSolveMatrix #-}

-- | Set @x := a^{-1} y@.
doSolveVector :: (MSolve a m, ReadVector y m, WriteVector x m, BLAS2 e) =>
    a e -> y e -> x e -> m ()
doSolveVector a y x =
    checkMatVecSolvTo (shape a) (dim y) (dim x) $
        unsafeDoSolveVector a y x
{-# INLINE doSolveVector #-}

-- | Set @b := a^{-1} c@.
doSolveMatrix :: (MSolve a m, ReadMatrix c m, WriteMatrix b m, BLAS3 e) =>
    a e -> c e -> b e -> m ()
doSolveMatrix a c b =
    checkMatMatSolvTo (shape a) (shape c) (shape b) $
        unsafeDoSolveMatrix a c b
{-# INLINE doSolveMatrix #-}

-- | Set @x := a^{-1} (alpha y)@.
doSSolveVector :: (MSolve a m, ReadVector y m, WriteVector x m, BLAS2 e) =>
    e -> a e -> y e -> x e -> m ()
doSSolveVector alpha a y x =
    checkMatVecSolvTo (shape a) (dim y) (dim x) $
        unsafeDoSSolveVector alpha a y x
{-# INLINE doSSolveVector #-}

-- | Set @b := a^{-1} (alpha c)@.
doSSolveMatrix :: (MSolve a m, ReadMatrix c m, WriteMatrix b m, BLAS3 e) =>
    e -> a e -> c e -> b e -> m ()
doSSolveMatrix alpha a c b =
    checkMatMatSolvTo (shape a) (shape c) (shape b) $
        unsafeDoSSolveMatrix alpha a c b
{-# INLINE doSSolveMatrix #-}

-- | Set @x := a^{-1} x@.
doSolveVector_ :: (MSolve a m, ReadVector y m, WriteVector x m, BLAS2 e) =>
    a e -> x e -> m ()
doSolveVector_ a x =
    checkSquare "doSolveVector_" (shape a) $
        checkMatVecSolv (shape a) (dim x) $
            unsafeDoSolveVector_ a x
{-# INLINE doSolveVector_ #-}

-- | Set @x := a^{-1} (alpha x)@.
doSSolveVector_ :: (MSolve a m, WriteVector x m, BLAS2 e) =>
    e -> a e -> x e -> m ()
doSSolveVector_ alpha a x =
    checkSquare ("doSSolveVector_ " ++ show alpha) (shape a) $
        checkMatVecSolv (shape a) (dim x) $
            unsafeDoSSolveVector_ alpha a x
{-# INLINE doSSolveVector_ #-}

-- | Set @b := a^{-1} b@.
doSolveMatrix_ :: (MSolve a m, WriteMatrix b m, BLAS3 e) =>
    a e -> b e -> m ()
doSolveMatrix_ a b =
    checkSquare "doSolveMatrix_" (shape a) $
        checkMatMatSolv (shape a) (shape b) $
            unsafeDoSolveMatrix_ a b
{-# INLINE doSolveMatrix_ #-}

-- | Set @b := a^{-1} (alpha b)@.
doSSolveMatrix_ :: (MSolve a m, WriteMatrix b m, BLAS3 e) =>
    e -> a e -> b e -> m ()
doSSolveMatrix_ alpha a b =
    checkSquare ("doSSolveMatrix_ " ++ show alpha) (shape a) $
        checkMatMatSolv (shape a) (shape b) $
            unsafeDoSSolveMatrix_ alpha a b
{-# INLINE doSSolveMatrix_ #-}