Skip to content

Instantly share code, notes, and snippets.

View eagletmt's full-sized avatar

Kohei Suzuki eagletmt

View GitHub Profile
@eagletmt
eagletmt / main.rs
Created February 13, 2022 10:45
Deserializing multiple (and optional) internally tagged values
fn main() {
for j in [
r#"{"type": "foo", "subtype": "bar", "a": 1}"#, // Deserialize to Foo(Bar(...))
r#"{"type": "foo", "subtype": "baz", "b": "1"}"#, // Deserialize to Foo(Baz(...))
r#"{"type": "foo", "c": true}"#, // Deserialize to Foo(Qux(...))
r#"{"type": "foo", "subtype": "other", "c": true}"#, // Error
r#"{"type": "hoge", "subtype": "fuga", "d": 2}"#, // Deserialize to Hoge(Fuga(...))
r#"{"type": "hoge", "subtype": "piyo", "e": 3}"#, // Deserialize to Hoge(Piyo(...))
] {
let s = serde_json::from_str::<S>(j);
std.join(' + ', [std.format('{ xs+: [%d] }', i) for i in std.range(0, 10000)])
% psql -c 'create table t (x integer not null)'
CREATE TABLE
% psql -c 'insert into t (x) values (0)'
INSERT 0 1
% psql -c 'select * from t'
 x
---
 0
(1 row)
@eagletmt
eagletmt / input.json
Created April 13, 2020 13:30
How to deserialize internally tagged JSON in Go?
{
"items": [
{"type": "A", "foo": "bar"},
{"type": "B", "hoge": "fuga"}
]
}
use rayon::prelude::*;
fn main() {
std::thread_local!(static CLIENT: std::cell::RefCell<Option<reqwest::Client>> = std::cell::RefCell::new(None));
rayon::ThreadPoolBuilder::new()
.num_threads(8)
.build_scoped(
|thread| {
CLIENT.with(|c| {
*c.borrow_mut() = Some(reqwest::Client::new());
extern crate env_logger;
extern crate rusoto_ec2;
fn main() {
use rusoto_ec2::Ec2;
env_logger::init();
// my VPC case in ap-northeast-1 region
let image_id = "ami-7a1be605";
require 'json'
require 'net/http'
require 'hako/script'
module Hako
module Scripts
class JenkinsTag < Script
JENKINS_BASE = 'https://jenkins.example.com'
TARGET_TAG = 'jenkins'
extern crate rusoto_core;
extern crate rusoto_sqs;
extern crate rusoto_s3;
extern crate rusoto_route53;
fn main() {
use rusoto_sqs::Sqs;
use rusoto_s3::S3;
use rusoto_route53::Route53;
@eagletmt
eagletmt / main.go
Last active October 28, 2023 00:02
List installable Android SDK packages (similar to sdkmanager --verbose --list)
package main
import (
"encoding/xml"
"fmt"
"io/ioutil"
"log"
"net/http"
)
require 'set'
class InferType
def self.run(&block)
infer_type = InferType.new
infer_type.start
block.call
ensure
infer_type.finish
end