Skip to content

Instantly share code, notes, and snippets.

View TuxCoding's full-sized avatar

Alex (TuxCoding) TuxCoding

  • [::1]
View GitHub Profile
@TuxCoding
TuxCoding / to_hex.rs
Created December 9, 2016 14:11
Converts unsigned int to hex string
fn tohex(input: &[u8]) -> String {
#[inline]
fn hex(d: u8) -> char {
match d {
0...9 => (d + 0x30) as char,
10...15 => (d + 0x57) as char,
_ => unreachable!("unexpected value: {}", d),
}
}
HikariConfig databaseConfig = new HikariConfig();
String driverType = config.get("driverType");
String host = config.get("host");
String port = config.get("port");
String database = config.get("database");
String jdbcUrl = "jdbc:" + driverType + "://" + host + ':' + port + '/' + database;
databaseConfig.setJdbcUrl(jdbcUrl);
databaseConfig.setUsername("root");
@TuxCoding
TuxCoding / TokenGenerator.java
Created December 9, 2016 14:06
Random alphanumeric string generator
import java.security.SecureRandom;
public class TokenGenerator {
private static final char[] TOKEN_CHARACTERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
.toCharArray();
private final int size;
protected SecureRandom random = new SecureRandom();
@TuxCoding
TuxCoding / google-route-frame.js
Created December 9, 2016 13:56
Google Maps route from origin to destination as a frame
let url = "https://www.google.com/maps/embed/v1/directions?" +
"key=" + mapsApiKey + "&origin=" + origin + "&destination=" + destination;
@TuxCoding
TuxCoding / main.js
Created December 9, 2016 13:53
Electron useful modifications in the main startup script - http://electron.atom.io/
function createWindow () {
[...]
//hide the menu items for fullscreen usage
mainWindow.setMenu(null);
[...]
}
// This method will be called when Electron has finished
@TuxCoding
TuxCoding / OS.java
Created December 9, 2016 13:46
Tries to guess the host os based on the java os-name properties
import java.util.Locale;
public enum OS {
LINUX,
MACOS,
SOLARIS,
WINDOWS,
UNKNOWN;
private OS() {
@TuxCoding
TuxCoding / WGCustomFlags.java
Created December 9, 2016 13:45
Creates a new custom flag in WorldGuard and checks if the flag is set at the given location - https://dev.bukkit.org/projects/worldguard-custom-flags
package me.xeroun.mcmmoextras;
import com.mewin.WGCustomFlags.WGCustomFlagsPlugin;
import com.mewin.util.Util;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.flags.EnumFlag;
import com.sk89q.worldguard.protection.flags.SetFlag;
import java.util.Set;
@TuxCoding
TuxCoding / blink1.py
Created December 9, 2016 13:40
Simple beginner script to control your blink1 device - https://blink1.thingm.com/
#! /usr/bin/python3
from blink1.blink1 import Blink1
import time
COLOR = "ed8106"
COLOR_RGB = struct.unpack('BBB', bytes.fromhex(COLOR))
# Seconds
FADE_TIME = 500
@TuxCoding
TuxCoding / HealthColor.java
Created December 9, 2016 13:34
Gets a Minecraft color based on the given (rounded) percentage value. Where 10% means getHealthColor(1) and 25% means getHealthColor(2)
private TextColor getHealthColor(int percent) {
TextColor highlightColor;
switch (percent) {
case 1:
case 2:
highlightColor = TextColors.DARK_RED;
break;
case 3:
case 4:
highlightColor = TextColors.RED;
@TuxCoding
TuxCoding / .gitignore
Created December 9, 2016 13:30
Rust gitignore
# Generated by Cargo
# will have compiled files and executables
/target/
# IntelliJ
/.idea/
Rust-Test.iml
out/