Skip to content

Instantly share code, notes, and snippets.

View Kalimaha's full-sized avatar
🌒
not because they are easy, but because they are hard

Guido Barbaglia Kalimaha

🌒
not because they are easy, but because they are hard
View GitHub Profile
@Kalimaha
Kalimaha / eggs.test.ts
Last active December 16, 2020 03:36
Jest/TS: Mock a dependency of the entity under test
import { eggs, eggsAsync } from "../src/eggs";
import { spam, spamAsync } from "../src/spam";
jest.mock("../src/spam");
describe("Synchronous Implementation", () => {
describe("non-mocked", () => {
beforeEach(() => { (spam as jest.Mock).mockImplementationOnce((a: number) => 10 * a) });
it("performs some calculations", () => {
import { eggs } from "../src/eggs";
import { spam } from "../src/spam";
describe("normal", () => {
it("does some calculations", () => {
expect(eggs(3)).toEqual(72);
});
});
describe("mocked", () => {
@Kalimaha
Kalimaha / index.html
Last active September 16, 2020 04:11
Container Queries - super minimal example
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<script>
function listen() {
const ro = new ResizeObserver(entries => { for (let entry of entries) { entry.target.style.borderRadius = Math.max(0, 250 - entry.contentRect.width) + 'px'; } });
var elements = document.querySelectorAll('[adaptive]');
for (var element, i = 0; element = elements[i]; i++) { ro.observe(element); }
}
@Kalimaha
Kalimaha / migration.rb
Last active July 21, 2020 01:43
Zero downtime migration
################################################################################
# Please Note: this version requires https://github.com/khiav223577/in_batches #
################################################################################
class AddLifecycleWebPushPermittedToUsers < ActiveRecord::Migration
disable_ddl_transaction!
def up
ActiveRecord::Base.transaction do
add_column :users, :lifecycle_web_push_permitted, :boolean, default: nil
execute('ALTER TABLE users ALTER COLUMN lifecycle_web_push_permitted SET DEFAULT false')
@Kalimaha
Kalimaha / decompress.rb
Created July 15, 2020 05:46
Decompress binary content from VCR's YAML file
require 'json'
require 'zlib'
require 'yaml'
require 'base64'
abort('Please proide the absolute path to VCR YAML file') if ARGV.size < 1
begin
filepath = ARGV[0]
yaml = YAML.load(File.read(filepath))
package main
import (
"encoding/json"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
)
type MyResponse struct {
ResponseId string
package au.com.mebank.awesomeservice.performance
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.testcontainers.containers.GenericContainer
import org.testcontainers.images.builder.ImageFromDockerfile
class KGenericContainer(dockerImageName: ImageFromDockerfile):
GenericContainer<KGenericContainer>(dockerImageName)
{
"accountPan": "123",
"tokens": [
{
"tokenUniqueReference": "...",
"tokenNumber": "...",
"maskedTokenNumber": "...",
"correlationId": "...",
"currentStatusDescription": "...",
"currentStatusDateTime": "...",
@Kalimaha
Kalimaha / Original_VS_Monads.kt
Last active November 8, 2019 05:00
ESM mapper with monads
@Component
open class PushAccountMapper @Autowired
constructor(private val validator: Validator, private val objectMapper: ObjectMapper) : (String) -> CardProvisioningRequest {
@Throws(ServiceException::class)
override fun invoke(payload: String): CardProvisioningRequest {
try {
val request = objectMapper.readValue(payload, CardProvisioningRequest::class.java)
val violations = validator.validate(request)
@Kalimaha
Kalimaha / PushAccountErrorHandler.kt
Last active October 26, 2019 07:40
Test ServerResponse!
package au.com.mebank.integration.dwbfaprovisioning.operation.pushAccount
import au.com.mebank.integration.dwbfaprovisioning.errors.BFAProvisioningErrorSpecification
import au.com.mebank.integration.dwbfaprovisioning.models.MDESPushAccountResponse
import au.com.mebank.integration.reactivesoap.error.ServiceException
import org.springframework.http.MediaType
import org.springframework.web.reactive.function.BodyInserters
import org.springframework.web.reactive.function.server.ServerResponse
import reactor.core.publisher.Mono