Skip to content

Instantly share code, notes, and snippets.

@tinyzero4
tinyzero4 / Tracker.java
Created October 5, 2023 14:58
Tracker task
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentSkipListSet;
import java.util.concurrent.atomic.AtomicInteger;
import static java.lang.Integer.parseInt;
import static java.util.Objects.requireNonNull;
/**
* Host Tracker: Server names consist of an alphabetic host type (e.g. "apibox") concatenated with the server number, with server numbers allocated sequentially (so, "apibox:1", "apibox:2", etc. are valid hostnames). Write a tracking class with two operations, "allocate(hostType)" and "deallocate(hostName)". The former should reserve and return the next available hostname, while the latter should release that hostname back into the pool.
* For example:
@tinyzero4
tinyzero4 / Tracker.java
Created October 5, 2023 14:57
Tracker task
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentSkipListSet;
import java.util.concurrent.atomic.AtomicInteger;
import static java.lang.Integer.parseInt;
import static java.util.Objects.requireNonNull;
public class Tracker {
private final ConcurrentHashMap<String, AtomicInteger> byTypeCounters = new ConcurrentHashMap<>();
@tinyzero4
tinyzero4 / postgres-cheatsheet.md
Created March 6, 2019 11:54 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)

Postgres Cheatsheet

This is a collection of the most common commands I run while administering Postgres databases. The variables shown between the open and closed tags, "<" and ">", should be replaced with a name you choose. Postgres has multiple shortcut functions, starting with a forward slash, "". Any SQL command that is not a shortcut, must end with a semicolon, ";". You can use the keyboard UP and DOWN keys to scroll the history of previous commands you've run.

Setup

installation, Ubuntu

http://www.postgresql.org/download/linux/ubuntu/ https://help.ubuntu.com/community/PostgreSQL

@tinyzero4
tinyzero4 / polynomial.cpp
Created February 3, 2019 12:14
Fail: time limit exceeded. Execution time: 9.97s, limit: 5.00s
#include "test_runner.h"
#include "profile.h"
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
template<typename T>
@tinyzero4
tinyzero4 / lazy_value.cpp
Created January 25, 2019 15:08
Error: The LazyValue<T> class object must not construct an object of type T when it is created
#include "test_runner.h"
#include <functional>
using namespace std;
template<typename T>
class LazyValue {
public:
explicit LazyValue(std::function<T()> init) {
<?xml version="1.0" encoding="UTF-8"?>
<?ADF version="1.0"?>
<adf>
<prospect>
<id sequence="1" source="Edmunds Appraisals">1198184098</id>
<type>Contact Us</type>
<requestdate>2016-01-19T13:30:22-08:00</requestdate>
<vehicle interest="sell" status="used">
<year>2014</year>
<make>Honda</make>