Skip to content

Instantly share code, notes, and snippets.

@edjeordjian
edjeordjian / RewireMockLibraryExamples.js
Created March 13, 2022 16:29
Examples for mocking in Node with Rewire Library
// [Mock a class]
// (when calling myFile.myMethod(), ClassIWantToMockInMyFie will be replaced by MyMockClass)
const myFile = rewire("../src/myFile");
myFile.__set__( {
'ClassIWantToMockInMyFie': MyMockClass
} );
@edjeordjian
edjeordjian / SimplePostRequestInSpringBoot.java
Created September 4, 2021 00:47
Quick way to send a post message in Spring Boot.
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
public class SimplePostRequestInSpringBoot {
public void simplePost() {
RestTemplate client = new RestTemplate();
client.getMessageConverters().add(new StringHttpMessageConverter());
import matplotlib.pyplot as plt
from matplotlib.ticker import (MultipleLocator, AutoMinorLocator, FormatStrFormatter)
import math
import numpy as np
# Funciton that returns the next differential.
# In the case of the example:
# dy/dt = cos(t)
def f(t, y):
return math.cos(t)
@edjeordjian
edjeordjian / SpringBootFileToObjectMapper.java
Last active September 4, 2021 00:42
Map a file (for example, a JSON) into an object with a few lines of code in Spring Boot.
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.*;
import org.springframework.util.ResourceUtils;
import java.io.IOException;
public class FileLoaderExample {
public static <DTO> DTO getDto(String path, Class<DTO> clazz) {
DTO dto = null;
try {
@edjeordjian
edjeordjian / simple_custom_timestamp.cpp
Last active March 20, 2020 21:13
A simple way to create a customized timestamp in C++.
#include <ctime>
#include <bits/stdc++.h>
std::string getTimestamp(char* format) {
std::time_t epoch_time = std::time(nullptr);
std::stringstream stream;
stream << std::put_time( std::localtime(&epoch_time), format );
return stream.str();
}