Skip to content

Instantly share code, notes, and snippets.

async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.setGlobalPrefix('api');
config.update({
accessKeyId: '[your S3 Access key]',
secretAccessKey: '[your S3 secret]',
region: '[your S3 region]',
});
await app.listen(3000);
}
// many ifs
function performActions(actionName: string) {
if (actionName === "save") {
// save...
} else if (actionName === "update") {
// update ...
} else if (actionName === "delete") {
// delete...
}
}
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import * as os from 'os';
const cluster = require('node:cluster');
const numCPUs = os.cpus().length;
async function bootstrap() {
const app = await NestFactory.create(AppModule);
await app.listen(3000);
attachFile(event: any) {
const file: File = event.target.files?.[0];
if (file && this.isValid(file)) {
this.errorMessage = '';
const formData = new FormData();
formData.append('file', file, file.name);
const uploadFileHeaders = new HttpHeaders({
Accept: `application/json, text/plain, */*`,
});
this.httpClient
<input #fileInput type="file" class="file-input" [accept]="acceptedFileExtensions" (change)="attachFile($event)" />
<div class="row document-type">
<div class="col-xs-12">
<button class="fileButton" action="file" (click)="onSelectFile()" type="submit">Upload document</button>
allowed file types(JPG, PNG, GIF)
</div>
</div>
@Injectable()
export class FileService {
async uploadPublicFile(dataBuffer: Buffer, filename: string) {
try {
const s3 = new S3();
const uploadResult = await s3
.upload({
Bucket: 'file-uploads',
Body: dataBuffer,
Key: `${uuid()}-${filename}`
@Post('upload')
@UseInterceptors(FileInterceptor('file'))
async uploadFile(
@UploadedFile() file: Express.Multer.File,
@Request() req,
): Promise<any> {
const result = await this.fileservice.uploadPublicFile(
file.buffer,
file.originalname,
);
# create a simulator
xcrun simctl create "my first simulator" "iPhone X" com.apple.CoreSimulator.SimRuntime.iOS-14–5
# boot a simulator
xcrun simctl boot 64B94C27-A5BB-4B2A-8E6B-C48B1AFEF298
# shutdown
xcrun simctl shutdown 64B94C27-A5BB-4B2A-8E6B-C48B1AFEF298
# show content of a plist file
plutil -p "[HOME]/Library/Developer/CoreSimulator/Devices/[DEVICE_NAME]/data/Library/Preferences/.GlobalPreferences.plist"
// Firstly define the entities
type DataSchema = {
client: {
dto: { id: string, name: string},
entity: {clientId: string, clientName: string}
},
order: {
dto: { id: string, amount: number},
entity: {orderId: string, quantity: number}
export class cloneable {
public static deepCopy<T>(source: T): T {
return Array.isArray(source)
? source.map(item => this.deepCopy(item))
: source instanceof Date
? new Date(source.getTime())
: source && typeof source === 'object'
? Object.getOwnPropertyNames(source).reduce((o, prop) => {
Object.defineProperty(o, prop, Object.getOwnPropertyDescriptor(source, prop)!);
o[prop] = this.deepCopy((source as { [key: string]: any })[prop]);