Skip to content

Instantly share code, notes, and snippets.

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;
class RangeLock {
int n;
volatile ConcurrentHashMap<String, ReentrantLock> m;
@schaitanya
schaitanya / install-docker.md
Created October 19, 2020 14:37 — forked from npearce/install-docker.md
Amazon Linux 2 - install docker & docker-compose using 'sudo amazon-linux-extras' command

UPDATE (March 2020, thanks @ic): I don't know the exact AMI version but yum install docker now works on the latest Amazon Linux 2. The instructions below may still be relevant depending on the vintage AMI you are using.

Amazon changed the install in Linux 2. One no-longer using 'yum' See: https://aws.amazon.com/amazon-linux-2/release-notes/

Docker CE Install

sudo amazon-linux-extras install docker
sudo service docker start
func singleNumber(nums []int) int {
i := 0
for _, v := range nums {
i ^= v
}
return i
}
package main
import "fmt"
func main() {
fmt.Println(containsDuplicate([]int{1, 2, 3, 4}))
}
func containsDuplicate(nums []int) bool {
ret := make(map[int]bool, len(nums))
func rotate(nums []int, k int) {
k %=len(nums)
reverse(nums, 0, len(nums)-1)
reverse(nums, 0, k-1)
reverse(nums, k, len(nums)-1)
}
func reverse(nums []int, start, end int) {
package main
// You are given a string, s, and a list of words, words, that are all of the same length.
// Find all starting indices of substring(s) in s that is a concatenation of each word
// in words exactly once and without any intervening characters.
// s := "barfoothefoobarman"
// words := [2]string{"foo", "bar"}
// Output: [0,9]
func main() {
import "strings"
// strs := []string{"flower", "flow", "flight"} -> fl
// strs := []string{"c", "acc", "ccc"} -> ""
func longestCommonPrefix(strs []string) string {
if len(strs) < 1 {
return ""
}
prefix := strs[0]
@schaitanya
schaitanya / logstash.conf
Created May 7, 2018 20:31 — forked from magicdude4eva/logstash.conf
Port25 / PowertMTA Logstash / Graylog configuration
################################################################################
## Port25 Logstash configuration
##
## Logging configuration:
##
## <acct-file /var/log/pmta/acct.csv>
## delete-after 60d
## move-interval 5m
## max-size 500M
## records d,b,r,t,tq,f,rb,rs
@schaitanya
schaitanya / better-nodejs-require-paths.md
Created March 3, 2017 20:20 — forked from branneman/better-nodejs-require-paths.md
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

var Article = require('../../../models/article');

Those suck for maintenance and they're ugly.

Possible solutions

I agree the point you’re making here, 100%. However, a slight correction about Node’s APIs.

First of all, process.nextTick is actually first in, first out. Proof:

$ node -e 'process.nextTick(console.log.bind(console, 1)); process.nextTick(console.log.bind(console, 2))'
1
2