Skip to content

Instantly share code, notes, and snippets.

View genert's full-sized avatar
🌍
Global citizen

G genert

🌍
Global citizen
View GitHub Profile
@genert
genert / color.es6.js
Created June 30, 2015 14:00
Simple ES6 based color class, that has 2 functions: rgbToHex and hexToRgb.
class Color {
rgbToHex (r, g, b) {
return '#' + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
}
hexToRgb (hex) {
let arr = hex.slice(1).match(/.{1,2}/g);
return [parseInt(arr[0], 16), parseInt(arr[1], 16), parseInt(arr[2], 16)];
}
}
@genert
genert / fire.js
Created July 9, 2015 10:39
Codwars Grid Blast Javascript Solution
// THE BATTLEFIELD GRID
// ['top left', 'top middle', 'top right',
// 'middle left', 'center', 'middle right',
// 'bottom left', 'bottom middle', 'bottom right']
//
function fire(x,y) {
var xArray = ['left', 'middle', 'right'],
yArray = ['top', 'middle', 'bottom'];
return ((x == 1 && y == 1) ? 'center' : yArray[y] + ' ' + xArray[x]);
@genert
genert / base64.node.js
Created July 9, 2015 10:46
Codwars Node Base64 Challange Javascript Solution
String.prototype.toBase64 = function() {
return new Buffer(this.toString()).toString('base64');
};
String.prototype.fromBase64 = function() {
return new Buffer(this.toString(), 'base64').toString('utf8');
};
@genert
genert / bubbleSort.es6.js
Created July 18, 2015 17:16
bubbleSort.es6.js
class BubbleSort {
private Sorter (arrayList, order) {
var temp;
for (var i = 0; i < arrayList.length - 1; i++) {
for (var j = i; j < arrayList.length - i; j++) {
if ((order == 'asc' ? (arrayList[j-1] > arrayList[j]) : (arrayList[j-1] < arrayList[j]))) {
temp = arrayList[j-1];
arrayList[j-1] = arrayList[j];
arrayList[j] = temp;
}
function findSum () {
var sum = 0;
arguments.__proto__ = Array.prototype;
for (val of arguments) {
if (val < 0) return -1;
sum += val;
}
return sum;
}
@genert
genert / round.es6.js
Last active December 23, 2015 22:21
Rounding. Example Round(3.44444) => "3.44"
function Round (n) {
return Number(`${Math.round(`${n}e${2}`)}e-${2}`).toString();
}
@genert
genert / collectionsAndLINQ.cs
Last active September 27, 2016 08:13
Collections and LINQ
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1 {
class Program {
static void Main(string[] args) {
@genert
genert / abstract_factory.go
Last active October 14, 2017 20:48
Go design patterns
package creational
import (
"errors"
"fmt"
)
const (
LuxuryCarType = 1
CarFactoryType = 1
@genert
genert / consul_helpers.sh
Created April 25, 2018 07:22
AWS Lambda Consul service with KVs
#!/bin/sh
# enable fail-fast
set -e
# enable trace
set -x
CONSUL_IP="xxxxxxx"
CONSUL_BASE_URL="http://${CONSUL_IP}:8500/v1"
@genert
genert / README.md
Last active November 19, 2022 17:16
Consul + dnsmasq + vault

docker-compose up -d

DNS

Currently, output from the dnsmasq and dnsmasq-secondary servers are minimal. Verbosity of output can be increased for troubleshooting. Edit docker-compose.yml and add --log-queries to the dnsmasq command.

DNS client troubleshooting using Docker.