Skip to content

Instantly share code, notes, and snippets.

View nielsvaes's full-sized avatar

Niels Vaes nielsvaes

View GitHub Profile
@nielsvaes
nielsvaes / zip_folder_to_file.py
Created July 17, 2023 12:56
Zip a folder to a file
import os
import zipfile
def make_zipfile(output_filename, source_dir):
relroot = os.path.abspath(os.path.join(source_dir, os.pardir))
with zipfile.ZipFile(output_filename, "w", zipfile.ZIP_DEFLATED) as zip:
for root, dirs, files in os.walk(source_dir):
zip.write(root, os.path.relpath(root, relroot))
for file in files:
filename = os.path.join(root, file)
@nielsvaes
nielsvaes / versioner.py
Created August 30, 2022 08:04
Make local versions of files
import stat
import os
import shutil
import datetime
LOCAL_HISTORY = ".local_history"
AUTO_PREFIX = ".version__"
NAMED_PREFIX = ".named__"
READONLY = 33060
WRITABLE = 33206
@nielsvaes
nielsvaes / radio_beacon.lua
Created February 24, 2022 22:23
DCS - RadioBeacon
-- Let's create a beacon for a unit in distress.
-- Frequency will be 40MHz FM (home-able by a Huey's AN/ARC-131)
-- The beacon they use is battery-powered, and only lasts for 5 min
local UnitInDistress = UNIT:FindByName("CRASHED HELICOPTER")
local UnitBeacon = UnitInDistress:GetBeacon()
-- Set the beacon and start it
UnitBeacon:RadioBeacon("MySoundFileSOS.ogg", 40, radio.modulation.FM, 20, 5*60)
@nielsvaes
nielsvaes / change_tanker_speed.lua
Last active February 17, 2022 12:57
DCS - Change tanker speed
-- DCS lua
local tanker = GROUP:FindByName("TANKER")
local route = tanker:GetTaskRoute()
for _, each in pairs(route) do
tanker:I(each["x"])
tanker:I(each["y"])
end
@nielsvaes
nielsvaes / lase_target.lua
Created January 5, 2022 20:48
DCS MOOSE - Lase target
local recce = UNIT:FindByName("DRONE UNIT")
local lasing_drone = SPOT:New(recce)
local target = UNIT:FindByName("LASER TARGET")
lasing_drone:LaseOn(target, 1688, 600)
MESSAGE:New("Lasing Target!"):ToAll()
@nielsvaes
nielsvaes / spawn_from_mark.lua
Created January 4, 2022 18:06
DCS MOOSE - Spawn from Mark
---
--- Generated by EmmyLua(https://github.com/EmmyLua)
--- Created by niels.
--- DateTime: 1/4/2022 3:35 PM
---
local function split_string(str, delimiter)
local result = {};
for match in (str ..delimiter):gmatch("(.-)"..delimiter) do
table.insert(result, match);
@nielsvaes
nielsvaes / get_empty_groups.py
Created January 26, 2021 11:29
Finds all the empty groups in a Maya scene
import pymel.core as pm
def get_shape_nodes(node, intermediate=False):
if pm.nodeType(node) == "transform":
shape_nodes = pm.listRelatives(node, shapes=True, path=True)
found_shape_nodes = []
if shape_nodes is None:
return None
@nielsvaes
nielsvaes / load_hard_edges.py
Created January 4, 2021 17:00
Loading hard edges on selected mesh in Maya
load_hard_edges(hard_edge_info):
selection_list = om.MSelectionList()
dag_path = selection_list.getDagPath(0)
mfn_mesh = om.MFnMesh(dag_path)
# zip over the small 2 member lists to end up with 2 big lists.
edge_numbers, edge_hardness = zip(*hard_edge_info)
mfn_mesh.setEdgeSmoothings(edge_numbers, edge_hardness)
mfn_mesh.cleanupEdgeSmoothing()
@nielsvaes
nielsvaes / save_hard_edges.py
Created January 4, 2021 16:58
Saving hard edges in Maya
import maya.api.OpenMaya as om
def save_hard_edges():
selection_list = om.MSelectionList()
dag_path = selection_list.getDagPath(0)
edge_it = om.MItMeshEdge(dag_path)
hard_edge_info = []
while not edge_it.isDone():
# save a list of the edge number and a bool whether it's a soft edge