Skip to content

Instantly share code, notes, and snippets.

View dolegi's full-sized avatar

Dom Ginger dolegi

View GitHub Profile
@dolegi
dolegi / market.elm
Last active February 6, 2017 17:02
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
type alias Product = { name : String, singular : String, amount : Int, price : Int }
type alias Model =
{ products : List Product, cash : Int }
model : Model
@dolegi
dolegi / todo.elm
Last active February 7, 2017 17:09
Todo list with columns in elm
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Json.Decode as Json
type Position = ToBeDone | Doing | Completed
type alias Todo = { name : String, position : Position }
type alias Model =
{ todos : List Todo, newTodoName : String }
@dolegi
dolegi / tsconfig.json
Last active June 12, 2019 09:19
Modern tsconfig good default settings
{
"compilerOptions": {
"module": "commonjs",
"target": "es2017",
"outDir": "./build",
"esModuleInterop": true,
"resolveJsonModule": true,
"allowJs": false,
"sourceMap": true,
"strict": true,
@dolegi
dolegi / index.js
Created August 27, 2018 13:47
Web RTC example
const webrtc = require('wrtc');
const lzString = require('lz-string');
const readline = require('readline');
const dataChannelSettings = {
reliable: {
ordered: true,
maxRetransmits: 1
}
}
@dolegi
dolegi / maze.html
Created September 7, 2018 08:45
C64 maze generator
<pre style=line-height:.9;font-family:fantasy>
<script>
const lineLength = document.querySelector('body').offsetWidth/10
function writeLine() {
for(let i = 1; i < lineLength; i++) {
document.write(Math.random()<.5?"/":"\\")
}
}
@dolegi
dolegi / event_loop.js
Last active June 12, 2019 09:20
Event loop implementation (just the timers part)
function sleep (ms) {
return new Promise(resolve => setTimeout(resolve, ms))
}
class EventLoop {
constructor () {
this.timers = []
}
@dolegi
dolegi / Dockerfile
Last active June 12, 2019 09:18
dockerized nginx static file server with subdomain dynamic routing and gzip compression
FROM nginx:alpine
COPY default.conf /etc/nginx/conf.d/default.conf
RUN mkdir -p /usr/share/nginx/one
RUN mkdir -p /usr/share/nginx/two
COPY index.html /usr/share/nginx/one/index.html
COPY index2.html /usr/share/nginx/two/index.html
@dolegi
dolegi / goaccess.sh
Last active June 15, 2019 17:24
Goaccess live HTML server
goaccess /var/log/traefik/access.log --log-format='%h %^[%d:%t %^] "%r" %s %b "%R" "%u" %^ "%v" "%^" %Tms' --date-format=%d/%b/%Y --time-format=%T -o /tmp/report.html --real-time-html
{ echo -e "HTTP/1.1 200 OK\r\n\r\n"; cat /tmp/report.html; } | nc -lk 9090
@dolegi
dolegi / ascii_art.js
Last active June 26, 2019 16:09
Ascii Art Generator. `node index.js ./myfile.<png/jpg/gif>`
const jimp = require('jimp')
const ASCII = '`^\",:;Il!i~+_-?][}{1)(|\\/tfjrxnuvczXYUJCLQ0OZmwqpdbkhao*#MW&8%B@$'
const file = process.argv[2]
const invert = process.argv[3] === 'invert'
const brightnessAlgo = process.argv[4]
jimp.read(file)
.then(img => {
img = img.resize(160,80)
@dolegi
dolegi / Dockerfile
Created October 27, 2019 11:52
Command to keep docker container running
FROM alpine
ENTRYPOINT ["tail", "-f", "/dev/null"]