Skip to content

Instantly share code, notes, and snippets.

@zzpmaster
zzpmaster / main.dart
Last active June 13, 2023 12:59
flutter ModalBottomSheet update state
showModalBottomSheet(
context: context,
builder: (context) {
return ModalBottomSheet(this.selected, this.data, (selected, data) {
this.selected = selected;
this.data = data;
});
});
@zzpmaster
zzpmaster / formatBytes.dart
Last active June 4, 2024 23:11
convert bytes to kb mb in dart
static String formatBytes(int bytes, int decimals) {
if (bytes <= 0) return "0 B";
const suffixes = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
var i = (log(bytes) / log(1024)).floor();
return ((bytes / pow(1024, i)).toStringAsFixed(decimals)) +
' ' +
suffixes[i];
}
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.*;
public class JsonHelper {
public static Object toJSON(Object object) throws JSONException {
if (object instanceof Map) {
JSONObject json = new JSONObject();
public class FlexibleDateParser {
private List<ThreadLocal<SimpleDateFormat>> threadLocals = new ArrayList<ThreadLocal<SimpleDateFormat>>();
public FlexibleDateParser(List<String> formats) {
threadLocals.clear();
for (final String format : formats) {
ThreadLocal<SimpleDateFormat> dateFormatTL = new ThreadLocal<SimpleDateFormat>() {
protected SimpleDateFormat initialValue() {
SimpleDateFormat sdf = new SimpleDateFormat(format);
sdf.setLenient(false);
import { Injectable } from '@angular/core';
import { EventManager } from '@angular/platform-browser';
import { Subject, Subscription } from 'rxjs';
import { debounceTime, throttle, throttleTime } from 'rxjs/operators';
type TimeoutHandler = () => Function;
/**
* prevent debounce click
*/
@Injectable({
@zzpmaster
zzpmaster / date-mask.directive.ts
Last active March 22, 2021 02:24
input输入年月日时,自动转换为yyyy年MM月dd日,提交时yyyy-MM-dd格式
import {
Directive,
ElementRef,
forwardRef,
HostListener,
OnInit,
Renderer2
} from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
import * as moment from 'moment';
@zzpmaster
zzpmaster / number-mask.directive.ts
Last active September 13, 2021 09:59
Angular Directive - input框输入数字,自动千分位分割
import { CommonUtils } from 'src/shared/utils/common-utils';
import { DecimalPipe } from '@angular/common';
import {
Directive,
ElementRef,
forwardRef,
HostListener,
Input,
OnInit,
@zzpmaster
zzpmaster / format.sh
Last active March 22, 2021 02:51
Git - Convert all files to LF (Git提交代码 - 将所有文件格式转为LF格式)
ls -r -n -file | foreach{ (cat -encoding UTF8 $_ ) -join "`n" | set-content -encoding UTF8 $_ }
@zzpmaster
zzpmaster / app.component.ts
Created March 22, 2021 03:10
Angular Create multi-instance HttpClient
import { Component, Inject, InjectionToken } from "@angular/core";
import { HttpClient, HttpXhrBackend } from "@angular/common/http";
import { Observable } from "rxjs/Observable";
// import { CUSTOMER_HTTP_CLENT } from "./app.module";
export const CUSTOMER_HTTP_CLENT = new InjectionToken("xx");
@Component({
selector: "my-app",
template: `
@zzpmaster
zzpmaster / clone.ts
Created June 16, 2021 02:30
clone object
function shallowCopy<T>(origin: T): T {
return Object.assign(
Object.create(Object.getPrototypeOf(origin)),
origin
)
}
function shallowCopy2<T>(origin: T): T {
const obj = { ...origin };
Object.setPrototypeOf(obj, (origin as Object).constructor.prototype);