Skip to content

Instantly share code, notes, and snippets.

@yinyin
yinyin / print_yaml_event.c
Created August 19, 2020 04:04
Print content of libyaml `yaml_event_t` structure
#include <stdio.h>
#include "yaml.h"
static void print_yaml_event(yaml_event_t *event)
{
char *event_type;
switch (event->type)
{
case YAML_NO_EVENT:
@yinyin
yinyin / signal_handler_reentrance.py
Created September 16, 2019 17:19
An experiment of signal reentrance in Python
#!/usr/bin/env python
"""
The result of signal handler reentrance in Python 2.7 and 3.7 might different:
# For Python 2.7
The signal handler will run in order.
```
$ python2 signal_handler_reentrance.py
@yinyin
yinyin / node-run.sh
Created September 24, 2018 17:36
Wrapper script for running node.js from customized folder
#!/bin/bash
NODEBASEPATH=/PATH/TO/NODEJS/INSTALLATION
SUBJECTCMD=`basename "${0}"`
export PATH=${NODEBASEPATH}/bin:$PATH
exec ${SUBJECTCMD} "${@}"
@yinyin
yinyin / env-protobuf.sh
Created September 24, 2018 17:34
Set environment variables for Protocol Buffer
#!/bin/bash
# source ~/bin/env-protobuf.sh
OPT_BASE=~/bin/app
which protoc
if [ "$?" != "0" ]; then
export PATH=$PATH:${OPT_BASE}/protobuf-3.6.1/bin
echo "PATH=${PATH}"
fi
@yinyin
yinyin / main.go
Last active October 15, 2017 12:19
Go channel experiment: see if what would result in select under various channel conditions.
package main
/*
See if what would result in select under various channel conditions.
Outputs:
- On mode = 1 (worker-1): "Got error: error at 2017-10-15 19:33:00.687713221 ... (ok: true)"
- On mode = 2 (worker-2): "Got error: <nil> (ok: true)"
- On mode = 3 (worker-2): "Got error: <nil> (ok: false)"
- On mode = -9 (timeout): "Have context done."
@yinyin
yinyin / go-run.sh
Last active October 15, 2017 04:43
Wrapper script for Go
#!/bin/bash
GOBASEPATH=/PATH/TO/GO/INSTALLATION
SUBJECTCMD=`basename "${0}"`
exec ${GOBASEPATH}/bin/${SUBJECTCMD} "${@}"
@yinyin
yinyin / float_convert_for_grib.c
Last active August 13, 2017 17:27
Function to convert IEEE-754 float into IBM float for GRIB
#include <endian.h>
#include <stdint.h>
#include <stdio.h>
uint32_t to_grib_float(float r) {
union {
float f;
uint32_t i;
char c[4];
} r_input;
@yinyin
yinyin / env-dart.sh
Created July 5, 2017 16:04
Set environment variable for Dart
#!/bin/bash
# source ~/bin/env-dart.sh
OPT_BASE=~/bin/app
which dart
if [ "$?" != "0" ]; then
export PATH=$PATH:${OPT_BASE}/dart/dart-sdk/bin
echo "PATH=${PATH}"
cat ${OPT_BASE}/dart/dart-sdk/version
@yinyin
yinyin / retrieve_metadata.dart
Last active June 14, 2017 19:13
Retrieving annotated metadata
import 'dart:mirrors';
class ToDo {
final String who;
final String what;
const ToDo(this.who, this.what);
String toString() => "ToDo[${this.who}: ${this.what}]";
}
@yinyin
yinyin / asynchronous_experiment.dart
Last active June 14, 2017 19:15
Asynchronous with await and Future API
import "dart:async";
Future<DateTime> currentTime(int forExp) async {
DateTime now;
for (int i = 0; i < 3; i++) {
now = new DateTime.now();
print("- exp${forExp}:current-time[${i}] = ${now}");
}
return now;
}