Skip to content

Instantly share code, notes, and snippets.

View Roms1383's full-sized avatar
😊
I might not be available to respond, but I'll do my best !

Rom's Roms1383

😊
I might not be available to respond, but I'll do my best !
  • Chiang Mai, Thailand
View GitHub Profile
@Roms1383
Roms1383 / lib.rs
Created December 6, 2021 03:56
Rust - semi complex builder pattern sample
use std::marker::PhantomData;
#[allow(dead_code)]
fn main() {
let go = Builder::up()
.left(One { _ghost: PhantomData::<Yes> })
.build();
println!("{:#?}", go);
}
@Roms1383
Roms1383 / Code.gs
Created November 10, 2020 06:30
Google sheet : quickly replace CRYPTOFINANCE
// use as before: e.g. CRYPTOFINANCE("XLM/USD")
// there's no way to use CRYPTOFINANCE("BINANCE:XLM/USD") without a paid account, so I didn't implement it
const API_KEY = 'YOUR_COINMARKETCAP_API_KEY' // do not forget to replace it with your own API key ;)
const domain = 'https://pro-api.coinmarketcap.com';
const ticker = 'v1/cryptocurrency/quotes/latest';
const options = {
method: 'GET',
headers: {
'X-CMC_PRO_API_KEY': API_KEY,
}
@Roms1383
Roms1383 / barrel.js
Created November 8, 2020 03:47
Write a TypeScript barrel file from files found in directory
const path = require('path')
const fs = require('fs')
const source = process.env.PWD
const filenames = fs.readdirSync(source)
.filter(filename => filename.indexOf('.ts') !== -1 && filename !== 'index.ts')
.map(filename => filename.replace('.ts', ''))
const content = filenames
.map(filename => `export * from './${filename}'`)
.join('\n')
fs.writeFileSync(path.join(source, 'index.ts'), content, { encoding: 'utf8' })
@Roms1383
Roms1383 / app.module.test.ts
Created March 30, 2020 17:53
Medium - Combining decorators for easy data manipulation
import { Note } from '@kroms/notes/notes.entity'
import { NotesModule } from '@kroms/notes/notes.module'
import { User } from '@kroms/notes/users.entity'
import { INestApplication, Injectable, Module } from '@nestjs/common'
import { NestFactory } from '@nestjs/core'
import {
InjectRepository,
TypeOrmModule,
TypeOrmModuleOptions,
} from '@nestjs/typeorm'
@Roms1383
Roms1383 / validation.pipe.test.ts
Created March 27, 2020 17:09
Medium - Easy validation with Nest.js and Joi
import * as Joi from '@hapi/joi'
import { Body, Controller, Module, NotImplementedException, Post, UsePipes } from '@nestjs/common'
import { NestFactory } from '@nestjs/core'
import axios from 'axios'
import * as Joiful from 'joiful'
import { ValidationPipe } from './validation.pipe'
class Implicit {
@Joiful.string().required()
@Roms1383
Roms1383 / app.controller.ts
Created March 21, 2020 09:41
Medium - Demystifying some of Nest.js with Passport
import { AuthenticatedGuard, Unauthorized } from '@kroms/auth'
import { Controller, Get, UseFilters, UseGuards } from '@nestjs/common'
@Controller()
export class AppController {
@Get('secured-page')
@UseGuards(AuthenticatedGuard)
@UseFilters(Unauthorized) // beware here it requires LocalStrategy explicit export in AuthModule
async securedPage() {
console.log(`@AppController /secured-page`)
@Roms1383
Roms1383 / MyComponent.story.js
Last active March 30, 2023 06:19
Illustrator scripting - Trace image and export to SVG - reuse in Vue.js and Storybook
// example of usage with Storybook
import MyComponent from './MyComponent'
import data from '../json/my-exported-graphic.json'
// symbol id must match in MyComponent.vue
const convert = raw => `<svg xmlns="http://www.w3.org/2000/svg" display="none">
<symbol id="graphic">
${raw.paths.map(path => '<path fill="green" d="' + path + '"/>\n')}
</symbol>
@Roms1383
Roms1383 / main.tf
Last active January 19, 2020 06:43
Medium - Mate Terraform and Serverless
module "sls_user" {
source = "./microservice"
microservice_version = "1.0.0"
}
module "sls_product" {
source = "./microservice"
microservice_version = "1.0.0"
# microservice_active = false
}
@Roms1383
Roms1383 / .env
Created January 16, 2020 05:11
Medium - Dynamically matching files in Jest - using environment variable
JEST_FILES_PATTERN="spec"
// or JEST_FILES_PATTERN="test"
// or JEST_FILES_PATTERN="spec|test"
@Roms1383
Roms1383 / jest.config.integration.only.js
Last active January 16, 2020 04:47
Medium - Dynamically matching files in Jest - using different configuration files
module.exports = {
...require('./jest.config'),
testMatch: ['**/?(*.)+(test).js']
}