This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"date": "2018-11-02", | |
"open": 141.0716, | |
"high": 141.1014, | |
"low": 138.7762, | |
"close": 139.7898, | |
"volume": 7673303, | |
"unadjustedVolume": 7673303, | |
"change": -0.139114, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const brain = require("brain.js"); | |
const rawData = [ | |
{ | |
date: "2018-11-02", | |
open: 141.0716, | |
high: 141.1014, | |
low: 138.7762, | |
close: 139.7898, | |
volume: 7673303, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Benchmark from "benchmark"; | |
function useDelete() { | |
const obj = {}; | |
obj.a = 1; | |
obj.b = 2; | |
delete obj.b; | |
} | |
function useReflect() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const assert = require("assert"); | |
// When we change the contents of an object, we can see | |
// the change outside the function. | |
function f1(obj) { | |
obj.a += 1; | |
assert.deepStrictEqual(obj, { a: 2 }); | |
} | |
const obj1 = { a: 1 }; | |
f1(obj1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import net from "net"; | |
import { Duplex } from "stream"; | |
function createClient(socket) { | |
return new Duplex({ | |
read(size) { | |
// This function is called when the stream wants to pull more data in. | |
// In this chat application example, data reading is handled by the socket's 'data' event, | |
// so you might not need to implement anything here. | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Como visto em | |
// https://refactoring.guru/design-patterns/decorator | |
// https://www.youtube.com/watch?v=GCraGHx6gso | |
// Artifício para simular uma interface | |
// e obrigar a implementação dos métodos | |
class IRepository { | |
find(filter) { | |
throw new Error("Method 'find' must be implemented"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
In the realm of OOP, it's preferable for business logic to be in close proximity to the data it pertains to. | |
This not only aligns with the 'S' in the SOLID principles—emphasizing, that Single Responsibility is about segregating unrelated | |
duties but also about consolidating related ones. | |
The method outlined below leverages getters and setters to intercept data handling, thereby preventing the model from accepting | |
any invalid values. This ensures that an invalid product could never exist within the system. | |
It should be noted that the validations demonstrated here are simplistic and meant for illustrative purposes. | |
Such rudimentary checks would typically reside outside the domain class, shifted towards the outer layers of the architecture, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* The UniquePropertySet class is designed to manage a collection of objects, | |
* ensuring that each object is unique based on its properties and values | |
* rather than its reference in memory. | |
* | |
* Beware, though, that this implementation is not optimized for performance, | |
* and that the JSON.stringify method does not handle non-serializable values | |
* consistently, such as functions, undefined, or circular references, which | |
* will cause objects containing such values to not be handled correctly. | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class StringExtensions | |
{ | |
// Consecutive runs for "Foo Bar 0123456789" generated: | |
// xuc iih 3156679205 | |
// lzr xai 1153091860 | |
// xxm uoy 5532413549 | |
public static string Obfuscate(this string input) | |
{ | |
if (input == null) return null; | |
var obfuscated = new char[input.Length]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace NameIt | |
{ | |
public static class AwsCostExplorer | |
{ | |
private const string metricType = "BlendedCost"; | |
private static readonly RegionEndpoint regionEndpoint = RegionEndpoint.USEast1; | |
public static AwsCostStructure GetCostForAccount(string accessKey, string secretKey, Period period) | |
{ | |
var client = new AmazonCostExplorerClient( |
NewerOlder