Skip to content

Instantly share code, notes, and snippets.

@aSemy
aSemy / okio_utf_convert.md
Last active March 7, 2024 10:43
Okio convert UTF 8/16/32

Untested

import okio.*
import okio.ByteString.Companion.encodeUtf8
import org.snakeyaml.engine.v2.api.YamlUnicodeReader.CharEncoding
import org.snakeyaml.engine.v2.api.YamlUnicodeReader.CharEncoding.*
import kotlin.jvm.JvmName

/**
@aSemy
aSemy / kotlin_native_c_compile.md
Created January 23, 2024 14:45
Compile C libraries for Kotlin/Native

Kotlin/Native requires that C libraries are compiled with a specific verison of GCC.

You can use the GCC used by Kotlin/Native itself. These Gradle tasks will help with this.

Example usage

// build.gradle.kts
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
@aSemy
aSemy / kn_cpp_compilation.md
Last active August 18, 2023 14:05
Kotlin/Native: Compile C++ code to

Kotlin/Native has a utility, run_konan, that can be used to compile C/C++ code.

I've written two Gradle tasks, RunKonanClangTask and RunKonanClangTask, that can be used to compile JoltC. A lot of credit goes to https://github.com/michal-z for writing C wrappers for Jolt!

This Gist is very scrappy, and is missing a lot of information.

  • Kotlin 1.9.0
  • I've only tested it on Windows.
  • The Kotlin target must be set manually - is it possible to make this automatic?
  • While the .konan dir can be retrieved from a KGP util function, the path to konan_run file must be set manually (e.g. kotlin-native-prebuilt-windows-x86_64-1.9.0) - is it possible to make this automatic?
@aSemy
aSemy / kjs_type_union_properties.md
Last active March 14, 2024 00:16
Kotlin/JS TypeUnion properties

Hot new strat for defining type-union properties in Kotlin/JS

Demo

// SomeConfig is an external TypeScript interface
// it has a property with a type-union type, but don't implement it as a member...
external interface SomeConfig {
  // multiProp: number | string | Extension | ((string) => Extension | null)
}
@aSemy
aSemy / !Hide Dropbox icon in Windows 10 taskbar notification area README.md
Last active October 20, 2021 11:01
Hide Dropbox icon in Windows 10 taskbar notification area

Hide Dropbox icon in Windows 10 taskbar notification area

Stop the Dropbox icon from re-appearing in the Windows 10 taskbar notification area.

Dropbox icon in the Windows 10 taskbar tray icons

Every time Dropbox updates it overrides my preference and moves its icon from the 'hidden' icons to the always-visible icons.

I've written hide_dropbox_icon.ps1, a Powershell script that will undo this forced option, and make the Dropbox icon hidden.

public static Set<Rule> getRules(final GraphQLRuleService ruleService) {
final Set<Rule> rules = new HashSet<>();
// validate name not blank
rules.add(ruleService.stringNonBlank(UserRegisterMutator.REGISTER_ARGUMENT_NAME, "name"));
return rules;
}
@Component
public class UserRegisterMutator {
public static final String REGISTER_ARGUMENT_NAME = "userRegisterRequest";
/**
* @param userRegisterRequest Contains info about the user's registration, e.g. their name
*
* @return Always returns true, so potential attackers get no info. Valid attempts will get an email.
*/
@Autowired
public GraphQlSampleController(final GraphQLRuleService ruleService) {
// Schema generated from query classes
GraphQLSchema schemaFromAnnotated = new GraphQLSchemaGenerator()//
// setup the schema
// ...
.generate();
// set up field validation
@Service
public class GraphQLRuleService {
// fetches messages from appropriate .prop file
@Autowired
private final MessagesService messagesService;
public RuleSingle stringNonBlank(final String argumentName, final String fieldName) {
return new RuleSingle() {
@Override
public Optional<GraphQLError> applySingle(FieldAndArguments fieldAndArguments, FieldValidationEnvironment environment) {
@aSemy
aSemy / Rules.java
Last active June 1, 2018 14:28
A couple of utils for GraphQL validation rules
// Rule.java
public abstract class Rule
implements BiFunction<FieldAndArguments, FieldValidationEnvironment, Optional<Collection<GraphQLError>>> {
}
// RuleSingle.java
public abstract class RuleSingle extends Rule {
@Override
public final Optional<Collection<GraphQLError>> apply(FieldAndArguments fieldAndArguments,