Skip to content

Instantly share code, notes, and snippets.

@VonHeikemen
VonHeikemen / map_utils.lua
Last active March 27, 2022 16:15
Allows you to use lua functions with `vim.api.nvim_set_keymap` (for neovim 0.6.1 or lower)
local M = {}
local module_name = 'map_utils'
local fn_store = {}
local function register_fn(fn)
table.insert(fn_store, fn)
return #fn_store
end
function M.apply_function(id)
@ollieatkinson
ollieatkinson / Executable.swift
Created August 17, 2021 15:41
Simply execute shell commands from Swift
public struct Executable {
let url: URL
public init(_ filePath: String) {
url = URL(fileURLWithPath: filePath)
}
public init(_ url: URL) {
self.url = url
@etozzato
etozzato / puma.rb
Last active January 28, 2024 20:12
A section of config/puma.rb that will automatically generate a self-signed X509 certificate and provide https in development
if Rails.env.development?
FileUtils.mkdir_p(Rails.root.join('config', 'certs'))
key_path = Rails.root.join('config', 'certs', 'development.key')
crt_path = Rails.root.join('config', 'certs', 'development.crt')
unless File.exist?(key_path) && File.exist?(crt_path)
def cert_domain
'localhost' # Setting[:cookie_domain] || 'localhost'
end
@nicklockwood
nicklockwood / CodableVersioning.swift
Last active January 29, 2024 11:31
Example demonstrating how to use versioning for Codable structs
// This gist demonstrates how you can implement versioning for a Codable struct to support loading
// old serialized data after changing the structure. Notable features of this solution:
//
// * No need to make new properties optional, or to perform post-processing on the struct after
// loading in ordeer to populate missing values
// * No need to change the call site - from the outside this struct behaves just the same
// as if we had implemented codable directly in the normal way.
// * Versioning can be applied individually to parents or leaves in a larger tree of
// structs without affecting the other elements
// * This approach will work even if the original struct was not designed with versioning in mind
extension Optional {
public func or(throw error: @autoclosure () -> Error) throws -> Wrapped {
guard let wrapped = self else { throw error() }
return wrapped
}
}
extension String {
@windwp
windwp / livereload.lua
Created April 18, 2021 06:34
livereload for plugin development on lua
#Neovim Trick
Live Reload on plugin development and init.lua
# Demo
# How
* [ ] code
extension Result {
public func `catch`(_ handler: () throws -> Success) -> Result<Success, Error> {
flatMapError { _ in
.init { try handler() }
}
}
public func `catch`(_ handler: (Failure) throws -> Success) -> Result<Success, Error> {
flatMapError { error in
.init { try handler(error) }
@ollieatkinson
ollieatkinson / JSON.swift
Created March 15, 2021 09:42
Another JSON box implementation over `Any` type
struct JSON {
enum Index {
case ordinal(Int), key(String)
}
private(set) var any: Any?
init(_ any: Any? = nil) {
self.any = any
-- =============================================================================
-- lightline to lualine theme converter
-- Author: shadman
-- License: MIT License
-- =============================================================================
-- Instructions
-- 1. Source this file in neovim with lightline installed
-- 2. execute :lua light2lualine_theme_converter('theme_name')