Skip to content

Instantly share code, notes, and snippets.

View Diluka's full-sized avatar
💭
I may be slow to respond.

Diluka Diluka

💭
I may be slow to respond.
  • Parsec Tech
  • Chongqing, China
  • 02:16 (UTC +08:00)
View GitHub Profile
@Diluka
Diluka / XFactory.java
Created August 13, 2014 15:07
Create a product by it's interface's type
package test.util.x;
import java.util.HashMap;
import java.util.Map;
import test.AProduct;
import test.BProduct;
import test.util.Factory;
import test.x.XAProductImp;
import test.x.XBProductImp;
@Diluka
Diluka / getFrac.js
Created July 23, 2015 15:11
将浮点数转换为分数
function getFrac(n) {
if (!(n instanceof Number)) {
n *= 1;
}
if (n === 0) {
return [0, n];
}
var i = 1;
var flag = 1;
@Diluka
Diluka / GenerateInsertSQL.sql
Last active January 22, 2016 12:29
GenerateInsertSQL
/*
isNumeric - return 1/true if passed in string is numeric, false otherwise
Usage example: select isNumeric('2012-02-16'); => 0
*/
DROP FUNCTION IF EXISTS ajgl.isNumeric;
CREATE DEFINER =`root`@`%` FUNCTION `isNumeric`(s VARCHAR(255))
RETURNS TINYINT(4)
DETERMINISTIC
BEGIN
SET @match = '^(([0-9+-.$]{1})|([+-]?[$]?[0-9]*(([.]{1}[0-9]*)|([.]?[0-9]+))))$';
@Diluka
Diluka / color-adjust.ts
Created January 26, 2017 09:24
颜色处理-带色偏的灰度处理
function colorAdjustProcess(data, i) {
let R0 = 145, G0 = 170, B0 = 190; //基准色
let R = R0 / (R0 + G0 + B0), G = G0 / (R0 + G0 + B0), B = B0 / (R0 + G0 + B0); //分配比例
let L = 3; // 亮度增益倍率
//
let r = data[i] * 0.3086;
let g = data[i + 1] * 0.6094;
let b = data[i + 2] * 0.0820;
@Diluka
Diluka / typeorm-cls.patch.ts
Created March 22, 2019 03:22
Patch CLS support to typeorm using typeorm-transactional-cls-hooked
import { Repository } from 'typeorm';
import { BaseRepository, initializeTransactionalContext } from 'typeorm-transactional-cls-hooked';
initializeTransactionalContext();
for (const p of Object.getOwnPropertyNames(BaseRepository.prototype)) {
Object.defineProperty(Repository.prototype, p, Object.getOwnPropertyDescriptor(BaseRepository.prototype, p));
}
@Diluka
Diluka / transform.spec.ts
Created April 10, 2019 09:03
test if module options is effect on body transform in @nestjsx/crud
import { Controller, INestApplication, Injectable } from '@nestjs/common';
import { RepositoryService } from '../../src/typeorm';
import { Company, ormConfig, User, UserProfile } from '../../integration/typeorm/e2e';
import { Crud, Override, ParsedBody, ParsedParams } from '../../src/decorators';
import { InjectRepository, TypeOrmModule } from '@nestjs/typeorm';
import { CrudController, FilterParamParsed } from '../../src/interfaces';
import { Test } from '@nestjs/testing';
import * as supertest from 'supertest';
import { CrudModule } from '../../src/module';
import { CrudConfigService } from '../../src/module/crud-config.service';
@Diluka
Diluka / crud-swagger-enhancement.ts
Last active September 26, 2019 01:37
增强版的CRUD修饰器,整合常用的修饰器于一体,并且大量减少冗余的描述
/*
* Copyright under the Parsec Tech Co., Ltd. Version 1.0;
* you may not use this file except in compliance with the permit.
* Copyright (c) 2019 ChongQing Parsec Technology Corporation. All Rights Reserved.
* Version 1.0
*/
/*
* Created by Diluka on 2019-04-22.
*
@Diluka
Diluka / crud.controller.ts
Created September 19, 2019 14:57
CRUD common query for sequelize with routing-controllers
import {
Authorized,
BadRequestError,
BodyParam,
ForbiddenError,
JsonController,
NotFoundError,
Put,
QueryParam
} from "routing-controllers";
@Diluka
Diluka / reinstall-xcode-cli-tools.sh
Created May 29, 2020 03:16
No Xcode or CLT version detected!
sudo rm -rf $(xcode-select -print-path)
xcode-select --install
@Diluka
Diluka / typeorm-nestjs-logger.ts
Created July 7, 2020 02:33
Integrate the nestjs logger into typeorm
/*
* Created by Diluka on 2020-06-29.
*
*
* ----------- 神 兽 佑 我 -----------
* ┏┓ ┏┓+ +
* ┏┛┻━━━━━━┛┻┓ + +
* ┃ ┃
* ┣ ━ ┃ ++ + + +
* ████━████ ┃+