Skip to content

Instantly share code, notes, and snippets.

@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 / 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';
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({
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 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();
@zzpmaster
zzpmaster / formatBytes.dart
Last active February 8, 2024 18:51
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];
}
@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;
});
});