Skip to content

Instantly share code, notes, and snippets.

View gelin's full-sized avatar

Denis Nelubin gelin

View GitHub Profile
@gelin
gelin / invite_to_slack.py
Created February 20, 2020 15:48
Invite users to Slack
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
import csv
import requests
import time
# Create and register your app in Slack.
# You need the Legacy Token here: https://api.slack.com/custom-integrations/legacy-tokens
@gelin
gelin / DynamoDBNestedIncrement.kt
Created February 20, 2020 15:47
Increment nested number in DynamoDB
import com.amazonaws.services.dynamodbv2.document.PrimaryKey
import com.amazonaws.services.dynamodbv2.document.api.UpdateItemApi
import com.amazonaws.services.dynamodbv2.model.ConditionalCheckFailedException
fun UpdateItemApi.nestedIncrement(key: PrimaryKey, attribute: String, path: List<String>, increment: Int) {
tryToIncrement(key, listOf(attribute) + path, increment)
}
private fun List<String>.toPathExpression(): String =
mapIndexed { index, _ -> "#p$index" }.joinToString(".")
@gelin
gelin / Pair.java
Created February 20, 2020 15:44
A Pair of elements
/**
* A pair of any objects with correct equals() and hashCode() overridden.
* @param <T> type of the fist element of the pair
* @param <U> type of the second element of the pair
*/
public final class Pair<T, U> {
private final T first;
private final U second;
@gelin
gelin / snippet.md
Created February 20, 2020 15:43
OpenJDK 8 in Debian 8

You need to add the Backports repository where the OpenJDK 8 package is located.

Add the file /etc/apt/sources.list.d/backports.list with this content:

# Backports repository
deb  http://ftp.debian.org/debian jessie-backports main contrib non-free

(You may replace http://ftp.debian.org/debian with any closer mirror, or even http://httpredir.debian.org/debian.)

@gelin
gelin / java-systemd-jessie.md
Created February 20, 2020 15:40
Java Systemd Service on Debian Jessie

Java Systemd Service on Debian Jessie

Systemd

Make sure systemd is installed.

systemctl

This command should list all installed services.

@gelin
gelin / remove_old_file_from_slack.py
Created February 20, 2020 15:39
Script to delete old files from Slack
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
from urllib.parse import urlencode, urlparse, parse_qs
import webbrowser
import http.server
import socketserver
from datetime import datetime, timedelta
import requests
@gelin
gelin / cue-split.sh
Created February 20, 2020 15:38
Script to split flac/ape CD rips by cue data and encode tracks to ogg vorbis files
#!/bin/sh
# Script to split flac/ape CD rips by cue data and encode tracks to ogg vorbis files.
#
# Put the script to a directory in your PATH.
#
# And then go to a directory containing .cue file and .flac/.ape file and run the command:
# cue-split.sh
#
# Or if the .cue is not in utf-8, decode it providing the -c flag with the original encoding:
@gelin
gelin / UpsertTask.java
Created February 20, 2020 15:37
SOLID Java 8
public class UpsertTask {
private interface Executor {
void execute() throws TaskExecutionException;
}
private Executor executeMethod;
public void prepare() {
if (/*something*/) {
import java.util.HashMap;
import java.util.Map;
public class IocKeySample {
public static class Key<T> {
private final String key;
private Key(String key) {
@gelin
gelin / GenericsTest.java
Created February 20, 2020 15:34
Small test for generic method to return parametrized type
import java.util.HashMap;
import java.util.Map;
// http://stackoverflow.com/questions/3437897/how-to-get-a-class-instance-of-generics-type-t
public class GenericsTest {
public static class MyClass extends Object {
}