Skip to content

Instantly share code, notes, and snippets.

View chenasraf's full-sized avatar
🏃‍♂️
Freelancing

Chen Asraf chenasraf

🏃‍♂️
Freelancing
View GitHub Profile
@chenasraf
chenasraf / README.md
Last active October 8, 2023 20:17
Aardwolf MUSHclient alias collection
@chenasraf
chenasraf / README.md
Last active October 8, 2023 20:21
Aardwolf MUSHclient alias - easy cexits for direction and back

How to use

  1. Add this alias
    • regular expression: true
    • send to: script
  2. Use m[o|u] to open. For example: mou becomes mapper cexit open u;;u mue becomes mapper cexit cast knock e;;open e;;e and also adds sets higher cexit_wait to make sure it succeeds
  3. If it's successful, it will create the same cexit in the opposite way
@chenasraf
chenasraf / README.md
Last active October 1, 2023 22:21
nvim format with custom formatters support

nvim format with custom formatters support

This format function is great to use on any languages not supported by your current LSP or when you are trying to pass custom arguments.

This example shows how dart format can be used to reformat the current buffer (so the file save state is irrelevant), replace the buffer with the new contents, and put the cursor back in position.

We prevent the need to escape any variables or tokens inside by using bash heredoc

@chenasraf
chenasraf / compose.ts
Created April 1, 2023 18:57
TS compose fn
type FirstOf<T extends IOFn[]> = T extends [infer F extends (...args: any) => any, ...IOFn[]]
? Parameters<F>
: never
type LastOf<T extends IOFn[]> = T extends [...IOFn[], infer L extends (...args: any) => any]
? ReturnType<L>
: never
type IOFn<I extends any[] = any, O = any> = (...x: I) => O
type Composed<A extends IOFn[]> = (...x: FirstOf<A>) => LastOf<A>
export function compose<A extends IOFn[]>(...fns: A): Composed<A> {
@chenasraf
chenasraf / zod-utils.ts
Created March 22, 2023 09:01
Zod - Validate Specific Field from Schema (good for forms)
type R = Record<string | number, any>
export function parseFieldSafe<T extends Zod.AnyZodObject, K extends keyof Zod.infer<T>>(
obj: T,
key: K,
value: T[K],
): Zod.SafeParseReturnType<R, R> {
return obj.pick({ [key]: true as const }).safeParse({ [key]: value })
}
@chenasraf
chenasraf / _readme.md
Last active January 21, 2023 22:34
Nextcloud + Docker Compose + Nginx

Nextcloud using Nginx & Docker Compose

This sample config set includes:

  • Nextcloud setup using Docker-Compose
  • Nginx serves the Docker using reverse-proxy
  • Systemd service file (optional)

There are examples of the nginx config that include:

@chenasraf
chenasraf / README.md
Last active August 25, 2022 12:24
Java SDK version switcher

jver version switcher

A simple script to allow to switch easily between JDK versions on a single machine, in case several versions are needed.

Usage:

jver list # list all available versions in $BASE_DIR
jver 17 # switch to version 17
jver 17 -q # suppress output
[ +169 ms] executing: sysctl hw.optional.arm64
[ +38 ms] Exit code 0 from: sysctl hw.optional.arm64
[ +3 ms] hw.optional.arm64: 1
[ +8 ms] executing: [/Users/<user>/.flutter-src/] git -c log.showSignature=false log -n 1 --pretty=format:%H
[ +26 ms] Exit code 0 from: git -c log.showSignature=false log -n 1 --pretty=format:%H
[ ] 680962aa75a3c0ea8a55c57adc98944f5558bafd
[ +1 ms] executing: [/Users/<user>/.flutter-src/] git tag --points-at 680962aa75a3c0ea8a55c57adc98944f5558bafd
[ +107 ms] Exit code 0 from: git tag --points-at 680962aa75a3c0ea8a55c57adc98944f5558bafd
[ +1 ms] 2.12.0-4.1.pre
[ +16 ms] executing: [/Users/<user>/.flutter-src/] git rev-parse --abbrev-ref --symbolic @{u}
@chenasraf
chenasraf / multiline_logger.dart
Last active March 15, 2024 06:45
Logger with no character limit for Dart/Flutter, splits the line into multiple ones when it is too long
import 'package:logger/logger.dart';
class SplitConsoleOutput extends LogOutput {
/// Maximum length per line in the log. Any logs larger than this length
/// will be split into chunks and printed in sequence.
final int splitLength;
/// Set to `false` to disable splitting, or leave `null`/`true` to retain the
/// default behavior, which is to truncate the text.
///
@chenasraf
chenasraf / keycodes.js
Created January 12, 2016 18:02
All JS Key Codes (event.which) in object notation
KeyCodes = {
"BACKSPACE": 8,
"TAB": 9,
"ENTER": 13,
"SHIFT": 16,
"CTRL": 17,
"ALT": 18,
"PAUSE": 19,
"CAPS_LOCK": 20,
"ESCAPE": 27,