Skip to content

Instantly share code, notes, and snippets.

View gelin's full-sized avatar

Denis Nelubin gelin

View GitHub Profile
@gelin
gelin / cp4prology.py
Created February 20, 2020 15:32
Copy/convert audio files to car audio: convert file to mp3, apply mp3gain, convert tags to ascii
#!/usr/bin/python
# -*- coding: utf-8 -*-
from __future__ import print_function
import sys
import os
import os.path
import shutil
import subprocess
import glob
import org.junit.Test;
import java.text.DateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
import static org.junit.Assert.assertEquals;
@gelin
gelin / Hex.kt
Last active February 20, 2020 13:36
Extension functions to format bytes as Hex values in Kotlin
package ru.gelin.kotlin.util.hex
import java.security.MessageDigest
import kotlin.test.assertEquals
/**
* Extension functions to format bytes as Hex values.
*/
/**
@gelin
gelin / snippet.kt
Created February 20, 2020 13:35
Type inference in Kotlin for Android
//Java
newIntent.setData(intent.getParcelableExtra(Intent.EXTRA_STREAM)); //compilation error
newIntent.setData(intent.<Uri>getParcelableExtra(Intent.EXTRA_STREAM)); //explicit type declaration
newIntent.setData((Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM)); //explicit type cast
//Kotlin
newIntent.setData(intent.getParcelableExtra(Intent.EXTRA_STREAM)) //implicit type inference!
val stream = intent.getParcelableExtra(Intent.EXTRA_STREAM) //compilation error
val stream : Uri = intent.getParcelableExtra(Intent.EXTRA_STREAM) //explicit type inference
newIntent.setData(stream)
@gelin
gelin / 2html.py
Created February 20, 2020 13:29
Markdown to HTML converter for Blogger
#!/usr/bin/python3
import sys
import codecs
import hoep
from pygments import highlight
from pygments.lexers import get_lexer_by_name, guess_lexer
from pygments.formatters import HtmlFormatter
import pyperclip
@gelin
gelin / snippet.html
Created February 20, 2020 13:21
InfluxDB query and chart with Rickshaw
<html>
<head>
<title>Test charts</title>
<script src="http://code.jquery.com/jquery-2.1.4.min.js" type="text/javascript"></script>
<script src="http://d3js.org/d3.v3.min.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/rickshaw/1.5.1/rickshaw.min.js" type="text/javascript"></script>
<script src="index.js" type="text/javascript"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/rickshaw/1.5.1/rickshaw.min.css" media="screen" rel="stylesheet" type="text/css">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" media="screen" rel="stylesheet" type="text/css">
@gelin
gelin / setup.json
Created February 20, 2020 13:15
Ansible Setup module run on Vagrant Ubuntu machine
{
"ansible_facts": {
"ansible_all_ipv4_addresses": [
"172.17.42.1",
"10.0.2.15",
"10.40.20.2"
],
"ansible_all_ipv6_addresses": [
"fe80::486d:2dff:fe59:74a2",
"fe80::5484:7aff:fefe:9799",
@gelin
gelin / print-badge_2x2
Last active September 20, 2019 04:01
Print 4 badges on a long sticker
#!/bin/sh
set -e
PRINTER="/dev/usb/lp0" # the printer device
FORCE=false
DIRECTION=1 # 1 - human-friendly, 0 - paper-friendly
DOTS_MM=8 # printer dots per mm, 8 == 203 dpi
@gelin
gelin / print-badge
Last active September 30, 2024 05:40
Python script to print a badge to a thermal printer with TSPL language (by TSC)
#!/usr/bin/env python3
PRINTER = '/dev/usb/lp0' # the printer device
DOTS_MM = 8 # printer dots per mm, 8 == 203 dpi
WIDTH_MM = 100 # sticker width, mm
HEIGHT_MM = 35 # sticker height, mm
GAP_MM = 2 # sticker gap, mm
FONT = "0" # built-in vector font, scalable by X and Y
@gelin
gelin / matplotlib.ipynb
Last active June 24, 2017 15:36
matplotlib examples
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.