Skip to content

Instantly share code, notes, and snippets.

View HallexCosta's full-sized avatar
:octocat:
Learning on-demand!

Hállex da Silva Costa HallexCosta

:octocat:
Learning on-demand!
View GitHub Profile
@HallexCosta
HallexCosta / instance.lua
Last active October 9, 2021 14:29
Generate a new instance in lua
local MyClass = {}
MyClass.__index = MyClass
setmetatable(MyClass, {
__call = function (cls, ...)
return cls.new(...)
end,
})
function MyClass.new(init)
@HallexCosta
HallexCosta / index.ts
Created July 18, 2021 06:07
Best practices to create Entities
export type Override<Original, Override> = Pick<
Original,
Exclude<keyof Original, keyof Override>
> &
Override;
type PartialEntity<T, K = Entity<T>> = Override<T, Partial<K>>;
abstract class Entity<EntityType> {
public readonly id: string;
@HallexCosta
HallexCosta / random-date.ts
Created July 12, 2021 17:23
Generate Random Date
function randomDate(start: Date, end: Date) {
return new Date(
start.getTime() + Math.random() * (end.getTime() - start.getTime())
)
}
@HallexCosta
HallexCosta / shuffle-and-return-last-4-elements.js
Last active July 11, 2021 21:24
Shuffle and Return Last 4 Elements
function shuffle(array, amount = undefined) {
var m = array.length, t, i;
// While there remain elements to shuffle…
while (m) {
// Pick a remaining element…
i = Math.floor(Math.random() * m--);
// And swap it with the current element.
@HallexCosta
HallexCosta / README.md
Last active May 30, 2021 04:38
Array Values to Key-Value Pairs

Array Values to Key-Value Pairs

const arrayValues = ["blue", 1, "red", 4, "yellow", 2, "green", 7]

const arrayObjects = []

for (let i = 0; i < arrayValues.length; i += 2) {
  const newObject = {}
 const key = arrayValues[i]
@HallexCosta
HallexCosta / README.md
Last active December 12, 2021 01:57
WSL2 Bridge Mode and XLaunch VcXsrv

Automate WSL Bridge Mode and XLaunch VcXsrv

Step 1

Select Task Schedule Library and click in Import Task...

import-task

Step 2

Select file wsl2-bridge-task-schedule.xml and open.

@HallexCosta
HallexCosta / bash.md
Last active May 18, 2021 22:36
Bash Advanced Commands

Bash Advanced Commands

Getting Started

  • I/O Redirection
    • >/dev/null

Usage

This is a example of use the function I/O Redirection in conditional structure

@HallexCosta
HallexCosta / create-write-wsl.conf
Last active May 3, 2021 16:11
Set default root dir in WSL
# Or use the command for create and write in file
cat >/etc/wsl.conf <<EOL
# Enable extra metadata options by default
[automount]
enabled = true
root = ~/
options = "metadata,umask=22,fmask=11"
mountFsTab = false
# Enable DNS – even though these are turned on by default, we'll specify here just to be explicit.
@HallexCosta
HallexCosta / move-commit-on-top.md
Last active April 25, 2021 21:54
Example of how to move commit "on top"

Move commit "on top"

# main:    A--B--X--Y
# feature: A--B--$--C--D

# new feature: A--B--C--D--$

# example to use command:
# git rebase -i {commitHash}~{moveToPosition}
@HallexCosta
HallexCosta / script.js
Created April 6, 2021 12:09
Recursive division using only subtraction and addition
/*
* @param a int {Amount to be divided}
* @param b int {Number of times the @ param1 value will be divided}
*/
function recursive_division (a, b){
if (b == 0)
throw new Error('Cannot divide by zero')
else if (a < b)
return [0, a]
else