Skip to content

Instantly share code, notes, and snippets.

View Nifled's full-sized avatar
👀

Erick Delfin Nifled

👀
View GitHub Profile
@Nifled
Nifled / app.ts
Created May 8, 2019 22:10
Getter/Setters with ES5/ES6 in TypeScript
// ES5
var Element = (function() {
function Element() {
this._class = null;
}
Object.defineProperty(Element.prototype, 'className', {
get: function() {
return this._class;
},
set: function(name) {
@Nifled
Nifled / commit-msg
Last active April 7, 2022 05:35
Script to automatically add JIRA ticket reference as a prefix to commit messages. File must be within project's `/.git/hooks/`
#!/bin/sh
#
# Commit hook to add a JIRA ticket reference as a prefix to any commit messages.
# NOTE: JIRA ticket number MUST be included in branch name or it does nothing...
# Doesn't make any specific checks, just does it.
BRANCH_NAME=$(git branch | grep '*' | sed 's/* //')
REGEX_TICKET_ID='(SOFT-[0-9]{4})' # SOFT can be replaced by any JIRA team name
# Do the regex search
@Nifled
Nifled / BaseModel.ts
Last active July 5, 2023 00:09
Serializing objects with unusual properties (Set, Date, any custom class, etc) to proper JSON-compatible objects.
// ...... other BaseModel code
/**
* Recursively serialize properties through class getters
* Returns ready object for JSON.stringify()
*/
public toJSON(): any {
const proto = Object.getPrototypeOf(this);
const jsonObj = {
[BaseModel.umt]: proto.constructor.universalModelType()
@Nifled
Nifled / tracker.js
Created March 30, 2023 20:11
Coding challenge from BEON
class Tracker {
_servers = [];
/**
*
* @param {string} hostType
* @example
* allocate("south")
*/
allocate(hostType) {
-----------------
TMUX CHEATSHEET
-----------------
Prefix for commands and help:
Ctrl-b and sth: issue a command to tmux, inside tmux.
Ctrl-b and ?: see all commands.
-------------------------------------------------------------------
Session commands:
@Nifled
Nifled / errors.ts
Last active June 1, 2023 19:23
Format array of `ValidationError` similar to `class-validator`'s default format. This is handy when creating calling `validate` (which returns `ValidationError[]`
import { validate } from 'class-validator';
const validationErrors = await validate(objInstance);
if (validationErrors.length > 0) {
throw new BadRequestException(
validationErrors.map(
({ property, constraints }) =>
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
`${property}: ${Object.values(constraints!)[0]}`,