Skip to content

Instantly share code, notes, and snippets.

@adrianjost
adrianjost / tcp-server.py
Last active July 23, 2020 22:57
Python 3 TCP float (double) adder
import socket
import sys
""" based on https://pymotw.com/3/socket/tcp.html
modified by Adrian Jost"""
# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Bind the socket to the port
@adrianjost
adrianjost / tic_tac_toe.js
Last active October 13, 2022 20:17
JS console.log() Tic-Tac-Toe Game
/*
* Created by Adrian Jost
* Feel free to use, but please credit me
*
* Start the game by calling `ttt()`
*/
function drawBoard(round, board){
console.group(`Score after round ${round}`);
console.log(" ");
console.log(' ' + (board["7"] || '7 ') + " | " + (board["8"] || ' 8 ') + " | " + (board["9"] || ' 9 '));
@adrianjost
adrianjost / turbonav.js
Last active November 4, 2018 12:29
turbonav inspired by turbolinks & swup
import diffDom from 'diff-dom'; // node-module: "npm i diff-dom"
const diffDOM = new diffDom();
const defaultOptions = {
clickTarget: `a[href*='${window.location.hostname}'], a[href^='#'], a[href^='/']`,
saveHeaders: `.turbonav-keep`,
imitateBrowserEvents: true
};
var options;
@adrianjost
adrianjost / md2tex.js
Last active June 24, 2019 09:17
Modernthesis Markdown to Latex converter
// Copyright (C) 2019 Adrian Jost
// This code is licensed under MIT license (see https://tldrlegal.com/license/mit-license for details)
const fs = require("fs");
const readFile = filename => {
return new Promise((resolve, reject) => {
fs.readFile(filename, "utf8", function(err, data) {
if (err) {
reject(err);
@adrianjost
adrianjost / filetreeFromDropEvent.js
Created July 20, 2019 11:59
How to create a filetree from the webbrowser drop event.
const traverseFiles = async (item) => {
if(item.isFile){
return { file: item.file(), path: item.fullPath };
}else if(item.isDirectory){
const entries = await new Promise(resolve => item.createReader().readEntries(resolve));
const files = await Promise.all(entries.map(traverseFiles));
return { path: item.fullPath, files };
}
}
@adrianjost
adrianjost / RenderHtml.vue
Created November 25, 2019 17:18
RenderHtml Component
<script>
// Cool way to render Vue components from HTML Strings
// https://medium.com/haiiro-io/compile-markdown-as-vue-template-on-nuxt-js-1c606c15731c
import VueWithCompiler from "vue/dist/vue.esm";
export default {
props: {
html: {
type: String,
default: "",
},
@adrianjost
adrianjost / ExtendedRenderHtml.vue
Last active November 25, 2019 17:37
How to extend the RenderHtml.vue
<script>
import RenderHtml from "./RenderHtml.vue";
import FancyButton from "@components/FancyButton.vue";
export default {
components: {
FancyButton,
},
...RenderHtml,
};
</script>
@adrianjost
adrianjost / aliases.config.js
Last active January 31, 2020 11:17
NuxtJS Theming - Component Alias - https://medium.com/p/2567ef5b5b6a
const path = require("path");
const aliases = {
// required to not break nuxt
"@": "src",
"@@": ".",
// custom aliases
"@components": "src/components",
}
@adrianjost
adrianjost / aliases.config.js
Last active January 31, 2020 11:17
NuxtJS Theming - Component aliases with theming - https://medium.com/p/2567ef5b5b6a
const glob = require("glob");
const path = require("path");
// returns a list of all filepaths in a given directory
const readDirRecursiveSync = dir => {
return glob.sync(`${dir}/**/*.*`);
};
const getThemeAliases = (dir, theme) => {
const themeFilesDir = `src/themes/${theme}/${dir}`;
@adrianjost
adrianjost / .github_workflows_sync.yml
Created May 13, 2020 08:07
Example: Files Sync Action - simple
name: Sync
'on':
schedule:
- cron: '0 3 * * *'
push:
branches:
- master
jobs:
files:
name: Files