Skip to content

Instantly share code, notes, and snippets.

import org.apache.flume.sink.elasticsearch.ContentBuilderUtil;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
public class JsonPlay {
public static void main(String[] args) throws Exception {
XContentBuilder strangeBuilder = XContentFactory.jsonBuilder().startObject();
ContentBuilderUtil.appendField(strangeBuilder, "data", "1\t{\"areYouSure\":\"thatItisvalidJson\"}".getBytes());
System.out.println(strangeBuilder.bytes().toUtf8());
public final class InVar {
private static final InheritableThreadLocal<String> S = new InheritableThreadLocal<String>() {
@Override
protected String childValue(String parentValue) {
System.out.println("Child called");
return parentValue + "b";
}
};
public static void main(String[] args) throws Exception {
use std::fs::File;
use std::io::{BufReader, Result};
use std::io::prelude::*;
type Instr = i32;
trait InstrOps {
fn is_immediate_param(self, nth: usize) -> bool;
}
use std::io::{Error, ErrorKind, Result};
use std::rc::Rc;
use std::cell::RefCell;
use crate::int_code::{IntCodeProg, OpResult};
fn perms_rec(res: &mut Vec<Vec<i64>>, vec: &mut Vec<i64>, from: usize) {
if from == vec.len() {
res.push(vec.clone());
} else {
for i in from..vec.len() {
extern crate num_complex;
extern crate ordered_float;
use std::fs::File;
use std::collections::HashSet;
use std::io::{BufRead, BufReader, Result};
use ordered_float::OrderedFloat;
use num_complex::Complex;
type Theta = OrderedFloat<f32>;
use std::fs::File;
use std::io::{BufRead, BufReader, Result};
use std::collections::{VecDeque, HashMap, HashSet};
type Pos = (i32, i32);
#[derive(Debug, Clone)]
enum Tile {
Free, Key(usize), Door(usize),
}
@whiter4bbit
whiter4bbit / main.rs
Created December 24, 2019 19:02
day 24b
use std::fs::File;
use std::io::{BufRead, BufReader, Result};
use std::collections::HashSet;
type Cell = (isize, isize, isize);
struct Grid {
rows: isize,
cols: isize,
bugs: HashSet<Cell>,
@whiter4bbit
whiter4bbit / main.rs
Created December 24, 2019 19:02
day 24b
use std::fs::File;
use std::io::{BufRead, BufReader, Result};
use std::collections::HashSet;
type Cell = (isize, isize, isize);
struct Grid {
rows: isize,
cols: isize,
bugs: HashSet<Cell>,
use std::fs::File;
use std::io::{BufRead, BufReader, Result};
use std::collections::HashSet;
type Grid = (i32, isize, isize);
fn load_grid(path: &str) -> Result<Grid> {
let f = File::open(path)?;
let f = BufReader::new(f);
@whiter4bbit
whiter4bbit / day4.rs
Last active December 4, 2020 14:05
AOC-2020: Day 4
use regex::Regex;
use std::io;
use std::ops::RangeInclusive;
use std::fs;
use std::collections::HashMap;
use std::str::FromStr;
fn match_re(re: &str, text: &str, captured_range: Option<RangeInclusive<i32>>) -> bool {
Regex::new(re).ok().and_then(|re|