Skip to content

Instantly share code, notes, and snippets.

View LucianoPAlmeida's full-sized avatar
💭
Daniel 11:32

Luciano Almeida LucianoPAlmeida

💭
Daniel 11:32
View GitHub Profile
// Awesome auto closures
class AwesomeType: CustomStringConvertible {
init() {
print("Initialize")
}
var description: String {
return "Description of an awesome type"
}
#include <iostream>
#include <array>
#include <vector>
int main(int argc, const char * argv[]) {
std::vector<int> numbers = {0, 2, 1, 4, 5, -2, 4};
std::sort(numbers.begin(), numbers.end(), std::greater<int>());
std::cout << "Descending: " << std::flush;
#include <iostream>
#include <array>
#include <vector>
int main(int argc, const char * argv[]) {
std::vector<int> numbers = {0, 2, 1, 4, 5, -2, 4};
std::stable_sort(numbers.begin(), numbers.end(), std::greater<int>());
std::cout << "Descending: " << std::flush;
#include <iostream>
#include <array>
#include <vector>
int main(int argc, const char * argv[]) {
std::vector<int> numbers = {0, 2, 1, 4, 5, -2, 3};
std::partial_sort(numbers.begin(), numbers.begin() + 4, numbers.end(), std::greater<int>());
std::cout << "Descending: " << std::flush;
struct Environment {
static var mySecretKey: String = Environment.variable(named: "SECRET_ENVIRONMENT_KEY") ?? CI.mySecretKey
static func variable(named name: String) -> String? {
let processInfo = ProcessInfo.processInfo
guard let value = processInfo.environment[name] else {
return nil
}
return value
struct CI {
static var mySecretKey: String = "$(SECRET_ENVIRONMENT_KEY)"
}
struct CI {
static var mySecretKey: String = "hsajeouisauiuoiueiwqoudasjlk"
}
@inline(never)
func increment<T: BinaryInteger>(_ t: T) -> T {
let incremented = t + 1
return incremented
}
var i: Int = 1
i = increment(i)
@_specialize(exported: true, where T==UInt)
func increment<T: BinaryInteger>(_ t: T) -> T {
let incremented = t + 1
return incremented
}
var i: Int = 1
i = increment(i)
@_semantics("optimize.sil.specialize.generic.never")
func increment<T: BinaryInteger>(_ t: T) -> T {
let incremented = t + 1
return incremented
}
var i: Int = 1
i = increment(i)