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');
};
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 / docker-compose.yml
Created May 14, 2019 12:26
Run graylog 3.0 locally
version: '2'
services:
# MongoDB: https://hub.docker.com/_/mongo/
mongodb:
image: mongo:3
volumes:
- mongo_data:/data/db
# Elasticsearch: https://www.elastic.co/guide/en/elasticsearch/reference/5.6/docker.html
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch-oss:6.6.1
import 'package:flutter/material.dart';
import 'package:english_words/english_words.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Startup Name Generator',