Skip to content

Instantly share code, notes, and snippets.

@vendethiel
vendethiel / hasDefinedKey.ts
Created March 26, 2025 16:46 — forked from AlexGeb/hasDefinedKey.ts
hasDefinedKey
export const hasDefinedKey =
<K extends PropertyKey>(key: K) =>
<T extends Partial<Record<K, unknown>>>(
obj: T,
): obj is T & Record<K, Exclude<T[K], undefined>> =>
key in obj && obj[key] !== undefined;
@vendethiel
vendethiel / main.p6
Created October 15, 2018 13:25 — forked from pmurias/main.p6
Hello World
say("Hello World");
@vendethiel
vendethiel / Commentated.scala
Last active May 26, 2020 11:02 — forked from SystemFw/Lib.scala
Shapeless: derive Slick's GetResult for arbitrary case classes
import slick.jdbc.{GetResult, PositionedResult}
import scala.annotation.implicitNotFound
import scala.reflect.runtime.universe.TypeTag
/**
* A type class that allows the user of GenericGetResult to support their own type.
* This is mostly used to support `newtype`s (like wrappers around UUIDs).
*
* A user just has to use the helper to make the type known to GenericGetResult.
my @a = ('99 bottles', 'take one down', '98 bottles');
for @a {
say "$^a of beer on the wall, $^a of beer.$^b, $^c of beer on the wall.".tc;
}
my @b = ('99 bottles', 'take one down', '98 bottles'), ('98 bottles', 'take one down', '97 bottles');
say @b.perl;
for @b {
say "$^a of beer on the wall, $^a of beer.$^b, $^c of beer on the wall.".tc;
}
macro $do {
rule {($($x = $y) (,) ...) $body} => {
(function ($x (,) ...) $body)($y (,) ...)
}
rule {$name ($($x = $y) (,) ...) $body} => {
(function $name ($x (,) ...) $body)($y (,) ...)
}
}
macro $var {
macro null_helper {
rule {($processed ...) ($rest)} => {
$processed (.) ... . $rest
}
rule {($processed ...) ($rest_head $rest ...)} => {
$processed (.) ... . $rest_head
&& null_helper ($processed ... $rest_head) ($rest ...)
}
}
// y-combinator
macro $y {
rule {( $var )} => {
function(){
return function (f){
return f(f)
}(function(f){
return $var(function(x){
return f(f)(x);
})
macro to_string {
case $x => { (JSON.stringify({ $x: 0 }).slice(2, -4)) }
}
macro enum {
case [ $val:ident (,) ... ] => {
(function () {
var e = {
$( $val : (to_string $val) ) (,) ...
};
@vendethiel
vendethiel / do.sjs
Last active January 2, 2016 01:29 — forked from int3/gist:4013740
coffee's do, fix for new sweet.js
macro $do {
rule {($($x = $y) (,) ...) $body} => {
(function ($x (,) ...) $body)($y (,) ...)
}
rule {$name ($($x = $y) (,) ...) $body} => {
(function $name ($x (,) ...) $body)($y (,) ...)
}
}
$do (a = 1, b = 2) {
@vendethiel
vendethiel / scheme.sjs
Last active January 2, 2016 01:29 — forked from disnet/scheme.sjs
scheme.sjs (forked from https://gist.github.com/disnet/3854258)
macro sexp {
rule {()} => {
;
}
rule {($p)} => {
$p
}
rule {($x $y)} => {
$x($y);
}