Skip to content

Instantly share code, notes, and snippets.

View david-bakin-sl's full-sized avatar

David Bakin david-bakin-sl

View GitHub Profile
@david-bakin-sl
david-bakin-sl / show-repo-branchs.sh
Created March 11, 2024 17:14
Show current branch of all repos under current directory
#!/usr/bin/env bash
# Show current branch for all repos under current directory (avoids submodules)
for repo in $(find . -type d -execdir test -d {}/.git \; -prune -print | sed 's/^\.\///g' | sort);
do
cd $repo
branch=$(git branch --show-current)
echo "$repo = $branch"
cd $OLDPWD
@david-bakin-sl
david-bakin-sl / UHK.kbd.json
Last active September 9, 2023 04:06
UHK Mac Qwerty - Base + Mod layers
[
{
"name": "UHK"
},
[
{
"c": "#459896"
},
"~\n\n\n\n\n\n`\n\n\n\nesc",
{
@david-bakin-sl
david-bakin-sl / getFileCreateTransactions.sh
Created August 24, 2023 21:06
Get all file create transactions from Hedera mirror node
OUT=fileCreateTransactions.json
MNODE=https://mainnet-public.mirrornode.hedera.com
echo '[' > $OUT
R=$(curl -S -s "${MNODE}/api/v1/transactions?transactionType=FILECREATE&result=success&order=asc")
echo ${R} , >> $OUT
while NEXT=$(echo $R | jq --exit-status --raw-output ' .links.next')
do
@david-bakin-sl
david-bakin-sl / removeLoggers.java
Created March 21, 2023 16:18
Remove all log4j2 appenders
private void removeLogging() {
final var ctx = (org.apache.logging.log4j.core.LoggerContext) LogManager.getContext(false);
final var configuration = (AbstractConfiguration) ctx.getConfiguration();
final var allAppenders = configuration.getAppenders();
for (final var appenderName : allAppenders.keySet()) {
configuration.removeAppender(appenderName);
}
}
@david-bakin-sl
david-bakin-sl / CloneViaSerialization
Created March 4, 2023 19:03
shallow copy via serialization
private Object copy(final Object src) {
byte[] intermediate = null;
try (final var bos = new ByteArrayOutputStream();
final var oos = new ObjectOutputStream(bos)) {
oos.writeObject(src);
oos.flush();
intermediate = bos.toByteArray();
} catch (IOException e) {
e.printStackTrace();
return null;
@david-bakin-sl
david-bakin-sl / CapturingLog4jMessagesForAUnitTest
Last active March 4, 2023 02:37
Capturing log4j messages for a unit test
@Test
void loggingCaptureTest() {
final var log = (org.apache.logging.log4j.core.Logger)LogManager.getLogger(Foobar.class); // whatever you use to get a logger
CharArrayWriter outContent = new CharArrayWriter();
StringLayout layout = PatternLayout.newBuilder().withPattern("%-5level %msg").build();
Appender appender = WriterAppender.newBuilder().setTarget(outContent).setLayout(layout).setName("TEST").build();
appender.start();
log.addAppender(appender);
log.setLevel(Level.DEBUG);
@david-bakin-sl
david-bakin-sl / #HelloHedera tutorial contract
Last active January 25, 2023 02:38
Hedera HelloHedera tutorial contract - Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.7+commit.e28d00a7.js&optimize=false&runs=200&gist=
From tutorial at https://docs.hedera.com/hedera/getting-started/try-examples/deploy-your-first-smart-contract