Skip to content

Instantly share code, notes, and snippets.

@robbdimitrov
robbdimitrov / links.txt
Last active August 31, 2022 15:10
Reading list
@robbdimitrov
robbdimitrov / rotate.js
Last active April 10, 2022 11:01
Image rotation
/**
* @param {number[][]} matrix
* @return {void} Do not return anything, modify matrix in-place instead.
*/
var rotate = function(matrix) {
const n = matrix.length;
for (let i = 0; i < Math.floor(n / 2); i++) {
for (let j = i; j < n - i - 1; j++) {
let positions = [
[j, n - 1 - i],
@robbdimitrov
robbdimitrov / Platform.java
Created November 22, 2021 09:45
Mobile platform and version discovery
package com.robbdimitrov.utils;
import java.util.regex.Pattern;
public class Platform {
public static boolean isIOS(String systemName) {
Pattern pattern = Pattern.compile("^(ios|iphone)", Pattern.CASE_INSENSITIVE);
return pattern.matcher(systemName).find();
}
@robbdimitrov
robbdimitrov / currency.py
Last active April 27, 2022 09:22
Problems
def convert(graph, start, end, path=None):
if path is None:
path = []
if start == end:
return 1
for child in graph:
if child[0] == start and child[0] not in path:
result = convert(graph, child[1], end, path + [child[0]])
@robbdimitrov
robbdimitrov / drag.js
Last active April 10, 2022 11:03
Drag and drop in React
const handleDragStart = (e) => {
e.preventDefault();
if (e.target.className.includes('draggable')) {
setSelected(e.target);
}
};
const handleDragEnd = (e) => {
e.preventDefault();
@robbdimitrov
robbdimitrov / pagination.js
Last active March 24, 2023 05:50
Pagination with dots
function getPages(maxPages, currentPage) {
let pages = [];
for (let i = 1; i <= maxPages; i++) {
if (i === 1 || i === maxPages ||
(currentPage < 4 && i <= 4) ||
(i >= currentPage - 1 && i <= currentPage + 1) ||
(maxPages - currentPage < 3 && maxPages - i <= 3)) {
pages.push(i);
} else if (pages[pages.length - 1] !== '...') {
@robbdimitrov
robbdimitrov / Crypto.java
Last active November 22, 2021 09:50
Symmetric AES encryption with Java
package com.robbdimitrov.crypto;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Arrays;
import java.util.Base64;
import javax.crypto.Cipher;
@robbdimitrov
robbdimitrov / resources.csv
Created October 6, 2020 19:03
Default AWS resuources
Identifier Tag: Name Service Type Region Tags
dopt-bab8c6c2 - EC2 DHCPOptions us-west-2 0
igw-2dc86254 - EC2 InternetGateway us-west-2 0
acl-e578a19e - EC2 NetworkAcl us-west-2 0
rtb-1057756b - EC2 RouteTable us-west-2 0
sg-6504684f - EC2 SecurityGroup us-west-2 0
subnet-1842ef45 - EC2 Subnet us-west-2 0
subnet-974fb3dd - EC2 Subnet us-west-2 0
subnet-fdc71585 - EC2 Subnet us-west-2 0
subnet-239db808 - EC2 Subnet us-west-2 0
@robbdimitrov
robbdimitrov / certs.md
Last active July 22, 2020 16:17
Certificates cheatsheet

Certificate cheatsheet

Naming

ca.pem - the root CA certificate
ca.pem - the CA private key
csr.pem - certificate signing request
cert.pem - client certificate
pkey.pem - client private key

package api
import (
"google.golang.org/grpc"
)
// Connector holds a pool of grpc connections
type Connector struct {
connections []*grpc.ClientConn
}