This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public struct Executable { | |
let url: URL | |
public init(_ filePath: String) { | |
url = URL(fileURLWithPath: filePath) | |
} | |
public init(_ url: URL) { | |
self.url = url |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Optional { | |
public func or(throw error: @autoclosure () -> Error) throws -> Wrapped { | |
guard let wrapped = self else { throw error() } | |
return wrapped | |
} | |
} | |
extension String { | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Neovim Trick | |
Live Reload on plugin development and init.lua | |
# Demo | |
# How | |
* [ ] code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct JSON { | |
enum Index { | |
case ordinal(Int), key(String) | |
} | |
private(set) var any: Any? | |
init(_ any: Any? = nil) { | |
self.any = any |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- ============================================================================= | |
-- 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') |