Skip to content

Instantly share code, notes, and snippets.

@lhns
lhns / unpackjdk.bat
Last active July 17, 2019 07:50
Batch script to unpack the jdk installer into a portable jdk folder
@echo off
set jdkinstaller=%1
for /F "tokens=* USEBACKQ" %%F in (`powershell -Command "'%jdkinstaller%' -replace '.*(?:\\|/)jdk-(\d)u(\d+)-.*','jdk1.$1.0_$2'"`) do (
set jdkpath=%%F
)
set PATH=%PATH%;C:\Program Files\7-Zip;C:\Program Files (x86)\7-Zip
var AudioContext = window.AudioContext || window.webkitAudioContext;
var audioCtx = new AudioContext();
notes = [
{key: "q", freq: 130.81, type: "square"},
{key: "2", freq: 138.59, type: "square"},
{key: "w", freq: 146.83, type: "square"},
{key: "3", freq: 155.56, type: "square"},
{key: "e", freq: 164.81, type: "square"},
{key: "r", freq: 174.61, type: "square"},
##########################################################################
CODE:
##########################################################################
import com.xtaudio.xt.*;
public class RenderSimple {
static double phase = 0.0;
static final double FREQUENCY = 660.0;
@lhns
lhns / shell.cmd
Last active April 20, 2018 08:36
Shell and Cmd compatible script
#!/usr/bin/env sh
:; shopt -s expand_aliases
:; alias ::=''
:: #SHELL
::
:: exit
@echo off
:: #CMD
exit /B
@lhns
lhns / universalScript.scala
Last active December 1, 2022 14:24
Cross platform scripts (scala script)
def universalScript(shellCommands: String,
cmdCommands: String,
shebang: Boolean): String = {
Seq(
if (shebang) "#!/usr/bin/env sh" else "",
"@ 2>/dev/null # 2>nul & echo off & goto BOF\r",
":",
shellCommands.replaceAll("\r?\n", "\n"),
"exit",
Seq(
#!/bin/bash
# path to tar file
# 1 input: path
# stdout: tar file
pathToTar() {
path="$1"
if [[ "$path" == /* ]]
then
tar -cf - --ignore-failed-read -C / "${path:1}"
:: Remove the error message produced by a shebang in a batch script
#!/bin/sh
@ 2>/dev/null # 2>nul & echo off & goto :BOF
:BOF
:: Remove shebang error message
setlocal EnableDelayedExpansion
:: Exclamation mark would be stripped
echo '#!/usr/bin/env sh'
cat
def defaultUniversalScript(javaOpts: Seq[String] = Seq.empty,
shebang: Boolean,
console: Boolean = true): Seq[String] = {
val javaOptsString = javaOpts.map(_ + " ").mkString
Seq(universalScript(
shellCommands = {
def javaCommand(args: String): String =
if (console) s"exec java $args"
else s"nohup java $args </dev/null &>/dev/null &"
@lhns
lhns / afterPrintCancelled
Created December 23, 2018 14:44
OctoPrint GCODE Scripts
; disable motors
M84
; disable all heaters
{% snippet 'disable_hotends' %}
{% snippet 'disable_bed' %}
;disable fan
M106 S0
; relative XYZE