Skip to content

Instantly share code, notes, and snippets.

@joshuaskelly
joshuaskelly / javascript_style_cheat_sheet.js
Last active May 22, 2019 04:46
JavaScript Style Cheat Sheet
/**
* JavaScript Style Cheat Sheet
* A short and sweet example of style, patterns, and practices.
*
* @author Joshua Skelton
*/
let Namespace = Namespace || {};
Namespace.Module = Namespace.Module || {};
{
"class": "com.interrupt.dungeoneer.entities.triggers.TriggeredShop",
"items": [
{
"class": "com.interrupt.helpers.ShopItem",
"item": {
"class": "com.interrupt.dungeoneer.entities.items.Food",
"itemType": "potion",
"foodType": "food",
"tex": "66",
@joshuaskelly
joshuaskelly / random_element_from_weighted_list.py
Last active August 20, 2017 17:08
Randomly select a value from a weighted list.
import random
from bisect import bisect
from itertools import accumulate
# The weighted list is represented as a sequence of weight-value pairs.
items = [(3, "apple"), (3, "banana"), (2, "cherry"), (1, "durian")]
# Build a list of weighted indexes.
weighted_indexes = list(accumulate([i[0] for i in items]))

QUAKE Tools & Editors

This is a curated list of interesting tools used to author content for Quake. If you know of tools that should be listed here please leave a comment.

bsp2map

A conversion utilility for quickly turning 2D .BMPs into 3D Quake .MAPs

http://www.siliconslick.com/bmp2map/

FraQuake

import bpy
import bmesh
me = bpy.data.meshes.new('test')
bm = bmesh.new()
bm.verts.new((0,0,0))
bm.verts.new((0,10,0))
bm.verts.new((10,10,0))
bm.verts.new((10,0,0))
import timeit
d = {"TWITCHCHATJOIN": 'JOIN',
"TWITCHCHATLEAVE": 'PART',
"TWITCHCHATMESSAGE": 'PRIVMSG',
"TWITCHCHATMODE": 'MODE',
"TWITCHCHATCLEARCHAT": 'CLEARCHAT',
"TWITCHCHATHOSTTARGET": 'HOSTTARGET',
"TWITCHCHATNOTICE": 'NOTICE',
"TWITCHCHATRECONNECT": 'RECONNECT',
@joshuaskelly
joshuaskelly / math.qc
Last active November 23, 2022 20:59
A QuakeC misc_model Implementation
/*
* MIT License
*
* Copyright (c) 2022 Joshua Skelton
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
@joshuaskelly
joshuaskelly / flat_unflat.py
Last active July 25, 2021 18:07
Example of Unstructuring and Structuring Pixel Data Using Python
# Flattening a sequence of structured data
image = ((1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4))
[rgb for pixel in image for rgb in pixel]
# >>> [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4]
# Structuring a sequence of flat data
image = (1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4)
it = iter(image)
tuple(zip(it, it, it))
# >>> ((1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4))

Pixel Perfect GIF to MP4 Conversion

problem

Sharing pixel art as animated gifs on social media sucks. Uploading animated gifs will typically get automatically converted to a video format with blurry results. We can manually do the conversion ourselves to get much nicer results.

solution

ffmpeg -i input.gif -movflags faststart -pix_fmt yuv420p -vf scale=1920:1080:flags=neighbor output.mp4