Skip to content

Instantly share code, notes, and snippets.

View chaoyangnz's full-sized avatar
🏠
Working from home

Chao Yang chaoyangnz

🏠
Working from home
View GitHub Profile
@iamgreaser
iamgreaser / boot.S
Last active April 21, 2024 09:04
RV64 QEMU virt VGA mode 13h
// riscv64-elf-gcc -Os -mcmodel=medany -nostdlib -march=rv64gc -Wl,-T,qemu.ld -o vga-hello.elf boot.S main.c
// qemu-system-riscv64 -machine virt -device VGA -smp 1 -kernel vga-hello.elf
.section .text
.global _start
.global _enter
_start:
_enter:
//1: j 1b
@baybatu
baybatu / mockito-deep-stubs.md
Last active September 21, 2020 07:48
Mockito deep stubs for nested objects
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private NestedObject nestedObject;

example usage in a test method:

when(nestedObject.getStatusInfo().getValue().getStatus()).thenReturn(1);
@rhamedy
rhamedy / README.md
Last active June 1, 2022 02:20
Configure HikariCP with Spring Boot JPA Hibernate and PostgreSQL as a database

I came across HikariCP and I was amazed by the benchmarks and I wanted to try it instead of my default choice C3P0 and to my surprise I struggled to get the configurations right probably because the configurations differ based on what combination of tech stack you are using.

I have setup Spring Boot project with JPA, Web, Security starters (Using [Spring Initializer][1]) to use PostgreSQL as a database with HikariCP as connection pooling.
I have used Gradle as build tool and I would like to share what worked for me for the following assumptions:

  1. Spring Boot Starter JPA (Web & Security - optional)
  2. Gradle build tool
  3. PostgreSQL running and setup with a database (i.e. schema, user, db)

This gist is related to SO post https://stackoverflow.com/questions/26490967/how-do-i-configure-hikaricp-in-my-spring-boot-app-in-my-application-properties-f

@paradite
paradite / paste.js
Last active January 24, 2023 10:48
intercept paste and do formatting in JavaScript (in Angular.js)
// tested in Chrome and Firefox
this.onPaste = function (event) {
if($(event.target).is(':focus')) {
// actually typing on the element, stop paste progation to outside paste handler
event.stopPropagation();
// intercept paste and format the text
event.preventDefault();
var newText = (event.originalEvent || event).clipboardData.getData('text/plain');
newText = newText.replace(/\r?\n/g, ' ');
@paulirish
paulirish / what-forces-layout.md
Last active April 30, 2024 17:56
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
@pbojinov
pbojinov / README.md
Last active December 8, 2023 21:09
Two way iframe communication- Check out working example here: http://pbojinov.github.io/iframe-communication/

Two way iframe communication

The main difference between the two pages is the method of sending messages. Recieving messages is the same in both.

Parent

Send messages to iframe using iframeEl.contentWindow.postMessage Recieve messages using window.addEventListener('message')

iframe

#!/usr/bin/ruby
# Create display override file to force Mac OS X to use RGB mode for Display
# see http://embdev.net/topic/284710
require 'base64'
data=`ioreg -l -d0 -w 0 -r -c AppleDisplay`
edids=data.scan(/IODisplayEDID.*?<([a-z0-9]+)>/i).flatten
vendorids=data.scan(/DisplayVendorID.*?([0-9]+)/i).flatten
@dgoguerra
dgoguerra / human-size.c
Last active November 29, 2023 03:08
Format a quantity in bytes into a human readable string (C)
#include <stdio.h>
#include <stdlib.h> // atoll
#include <stdint.h> // uint64_t
#include <inttypes.h> // PRIu64
static const char *humanSize(uint64_t bytes)
{
char *suffix[] = {"B", "KB", "MB", "GB", "TB"};
char length = sizeof(suffix) / sizeof(suffix[0]);