Skip to content

Instantly share code, notes, and snippets.

View hilios's full-sized avatar
🛠️
Breaking stuff

Edson Hilios hilios

🛠️
Breaking stuff
View GitHub Profile
@hilios
hilios / rpn.rs
Created February 1, 2024 17:25
RPN Calculator in RUST
use std::collections::VecDeque;
use crate::expr::Expr::*;
#[derive(Debug, Clone)]
enum Expr {
Number(f64),
Add(Box<Expr>, Box<Expr>),
Subtract(Box<Expr>, Box<Expr>),
Divide(Box<Expr>, Box<Expr>),
Multiply(Box<Expr>, Box<Expr>),
@hilios
hilios / Main.kt
Last active January 13, 2023 17:38
Sudoku solver (kotlin)
import kotlin.time.ExperimentalTime
import kotlin.time.measureTimedValue
@OptIn(ExperimentalTime::class)
fun main() {
val empty = listOf(
0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0,
@hilios
hilios / .vimrc
Created September 23, 2021 13:22
Vim config
## General
set number # Show line numbers
set linebreak # Break lines at word (requires Wrap lines)
set showbreak=+++ # Wrap-broken line prefix
set textwidth=100 # Line wrap (number of cols)
set showmatch # Highlight matching brace
set spell # Enable spell-checking
set visualbell # Use visual bell (no beeping)
set hlsearch # Highlight all search results
import org.scalatest.{FlatSpec, Matchers}
import scala.annotation.tailrec
class FraudioSpec extends FlatSpec with Matchers {
def maxTickets(tickets: Array[Int]): Int = {
@tailrec def select(current: Int, max: Int, tickets: Array[Int]): Int = tickets match {
case Array() => max
case Array(head, tail@_*) =>
@hilios
hilios / Hasher.scala
Last active June 27, 2019 20:04
Simple HMAC 236 hasher
import cats.data.Kleisli
import cats.effect.Sync
import com.google.common.io.BaseEncoding
import javax.crypto.spec.{IvParameterSpec, PBEKeySpec, SecretKeySpec}
import javax.crypto.{Cipher, SecretKeyFactory}
object Hasher {
type Key = (String, String)
final case class InvalidInputException(hash: String, ex: Throwable) extends IllegalArgumentException(s"Could not decrypt [$hash]", ex)
@hilios
hilios / Dockerfile
Created June 4, 2019 22:34
Let's Encrypt docker
FROM ubuntu:18.04
EXPOSE 80 443
COPY ./credentials.json /etc/credentials.json
RUN apt-get update \
&& apt-get install -y --no-install-recommends python-setuptools python-pip certbot lighttpd \
&& pip install -U --no-cache-dir pip certbot certbot-dns-google \
&& chmod a+rwx,u-x,g-rwx,o-rwx /etc/credentials.json \
@hilios
hilios / FutureConcurrentEffect.scala
Last active April 2, 2019 14:44
Effect[Future]
import scala.concurrent.{Await, ExecutionContext, Future, Promise}
import cats.implicits._
import scala.concurrent.duration.Duration
import scala.util.{Failure, Success}
final case class FutureConcurrentEffect()(implicit ec: ExecutionContext) extends FutureEffect with ConcurrentEffect[Future] {
def start[A](fa: Future[A]): Future[Fiber[Future, A]] = Future.successful {
FutureFiber(fa)
}
"""
Get the docker --name from inside a container.
$ pip install docker
"""
import docker
import subprocess
client = docker.from_env()
@hilios
hilios / HowToOTG.md
Created November 16, 2016 01:24 — forked from gbaman/HowToOTG.md
Simple guide for setting up OTG modes on the Raspberry Pi Zero

Raspberry Pi Zero OTG Mode

Simple guide for setting up OTG modes on the Raspberry Pi Zero - By Andrew Mulholland (gbaman).

The Raspberry Pi Zero (and model A and A+) support USB On The Go, given the processor is connected directly to the USB port, unlike on the B, B+ or Pi 2 B, which goes via a USB hub.
Because of this, if setup to, the Pi can act as a USB slave instead, providing virtual serial (a terminal), virtual ethernet, virtual mass storage device (pendrive) or even other virtual devices like HID, MIDI, or act as a virtual webcam!
It is important to note that, although the model A and A+ can support being a USB slave, they are missing the ID pin (is tied to ground internally) so are unable to dynamically switch between USB master/slave mode. As such, they default to USB master mode. There is no easy way to change this right now.
It is also important to note, that a USB to UART serial adapter is not needed for any of these guides, as may be documented elsewhere across the int

@hilios
hilios / README.md
Last active July 4, 2022 15:36 — forked from mhayes/supervisord.sh
init.d for supervisord for Amazon Linux AMI

Auto start for Supervisord at AWS

Install commands
$ sudo mv supervisor /etc/init.d
$ sudo chkconfig --add supervisor
$ sudo chkconfig supervisor on