Skip to content

Instantly share code, notes, and snippets.

View zmeyc's full-sized avatar

Andrey Fidrya zmeyc

  • https://www.door3.com
  • Ukraine
View GitHub Profile
@vzsg
vzsg / 1_JSONifyTag.swift
Last active March 11, 2023 18:49
Custom Leaf tag for printing anything in the context as JSON (Vapor 4)
import LeafKit
final class JSONifyTag: UnsafeUnescapedLeafTag {
func render(_ ctx: LeafContext) throws -> LeafData {
guard let param = ctx.parameters.first else {
throw "no parameter provided to JSONify"
}
return LeafData.string(param.jsonString)
}
@jstn
jstn / RandomNumbers.swift
Last active May 5, 2023 03:26
generate random numbers for 64-bit types while mitigating modulo bias
/*
`arc4random_uniform` is very useful but limited to `UInt32`.
This defines a generic version of `arc4random` for any type
expressible by an integer literal, and extends some numeric
types with a `random` method that mitigates for modulo bias
in the same manner as `arc4random`.
`lower` is inclusive and `upper` is exclusive, thus:
@40
40 / FileBrowse.hpp
Created June 29, 2012 05:58
Browse File System on BB10 Cascades Snippet
#ifndef FILEBROWSEDIALOG_HPP_
#define FILEBROWSEDIALOG_HPP_
#include <QThread>
#include <QVariant>
#include <bps/dialog.h>
/*
* The file browse dialog displays a dialog to browse and select
* files from shared folders on the system.