Skip to content

Instantly share code, notes, and snippets.

@benhoyt
benhoyt / markov.py
Created November 11, 2023 15:45
Generate text from an input using a simple Markov chain generator
import collections, random, sys, textwrap
# Build possibles table indexed by pair of prefix words (w1, w2)
w1 = w2 = ''
possibles = collections.defaultdict(list)
for line in sys.stdin:
for word in line.split():
possibles[w1, w2].append(word)
w1, w2 = w2, word
@younesbelkada
younesbelkada / finetune_sft_trl.py
Last active March 4, 2024 22:00
Benchmarking SFT trainer with 8bit models
# coding=utf-8
# Copyright 2023 The HuggingFace Inc. team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
@ronaldb
ronaldb / docker-compose.yml
Last active April 7, 2024 04:29
Docker - Use secrets in a single node docker environment and mysql
version: "3.6"
services:
my_sql:
image: mysql:5.7
volumes:
- ./data:/var/lib/mysql
secrets:
- my_secret
require('dotenv').config()
const http = require('http')
const express = require('express')
const session = require('express-session')
const FileStore = require('session-file-store')(session)
const bodyParser = require('body-parser')
const morgan = require('morgan')
const cors = require('cors')
const passport = require('passport')
@claytongulick
claytongulick / template.js
Last active June 25, 2022 23:32
if statement inside string template literals and lit-html.
//a quick example of how to use actual 'if' statements inside template literals,
//without using ternary operator. Sometimes this is cleaner if you have complex conditionals or nested conditionals.
//data param is passed in via render(template(data), this) - if not using lit-html, could be any function
template = (data) => html`
<div id="job_edit" class="modal">
<div class="modal-content">
${
//we're just going to wrap an anonymous inline function here and then call it with some data
(job => { //job here, is just an example, it could be anything, it's passed in below in (data.job)
if(job)
@NigelEarle
NigelEarle / Knex-Setup.md
Last active July 8, 2024 11:52
Setup Knex with Node.js

Knex Setup Guide

Create your project directory

Create and initialize your a directory for your Express application.

$ mkdir node-knex-demo
$ cd node-knex-demo
$ npm init

Generating Procedural Game Worlds with Wave Function Collapse

Wave Function Collapse (WFC) by @exutumno is a new algorithm that can generate procedural patterns from a sample image. It's especially exciting for game designers, letting us draw our ideas instead of hand coding them. We'll take a look at the kinds of output WFC can produce and the meaning of the algorithm's parameters. Then we'll walk through setting up WFC in javascript and the Unity game engine.

sprites

The traditional approach to this sort of output is to hand code algorithms that generate features, and combine them to alter your game map. For example you could sprinkle some trees at random coordinates, draw roads with a brownian motion, and add rooms with a Binary Space Partition. This is powerful but time consuming, and your original vision can someti

@hubgit
hubgit / youtube-gif.sh
Last active September 12, 2023 23:28
Convert a section of a YouTube video to an animated GIF
#!/bin/bash
# brew install x265
# brew install ffmpeg
# brew install youtube-dl
# brew install imagemagick
ID='U65_uY5N2WM' # YouTube video ID, i.e. https://www.youtube.com/watch?v={ID}
# fetch the video file with youtube-dl
@Cacodaimon
Cacodaimon / GameManager.js
Created December 3, 2012 00:54
Abstract game object class. (Used @ cacodaemon.de)
/*
* Simple JavaScript game manager.
*
* (c) 2012 Guido Krömer <mail@cacodaemon.de>
*
*/
function GameManager () {
var canvas = null;
var ctx = null;
var delta = 0;