Skip to content

Instantly share code, notes, and snippets.

View Nifled's full-sized avatar
👀

Erick Delfin Nifled

👀
View GitHub Profile
-----------------
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 / 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 / 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]}`,
@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) {
@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 / .hyper.js
Created August 23, 2018 08:33
dot files
// Future versions of Hyper may add additional config options,
// which will not automatically be merged into this file.
// See https://hyper.is#cfg for all currently supported options.
module.exports = {
config: {
// choose either `'stable'` for receiving highly polished,
// or `'canary'` for less polished but more frequent updates
updateChannel: 'stable',
@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 / css.json
Created October 22, 2018 07:15
styled-components vscode custom snippets
{
"Styled Component Media Query": {
"prefix": "media",
"body": [
"@media ($1-width: $2) {",
"\t$0",
"}"
],
"description": "Media Query"
},
@Nifled
Nifled / css.json
Created October 22, 2018 07:15
styled-components vscode custom snippets
{
"Styled Component Media Query": {
"prefix": "media",
"body": [
"@media ($1-width: $2) {",
"\t$0",
"}"
],
"description": "Media Query"
},
@Nifled
Nifled / javascriptreact.json
Last active October 19, 2018 08:54
React ES6 custom snippets for vscode
{
"Import React": {
"prefix": "imr",
"body": ["import React from 'react'"],
"description": "Import React"
},
"Import PropTypes": {
"prefix": "impt",
"body": ["import PropTypes from 'prop-types'"],