Skip to content

Instantly share code, notes, and snippets.

Callionica callionica

Block or report user

Report or block callionica

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@callionica
callionica / cpp.json
Last active Feb 14, 2017
VSCode Snippets for C++ from Callionica --- Visual Studio Code - VS Code - VSCode
View cpp.json
{
"include": {
"prefix": "#inc",
"body": [
"#include \"$1\"",
"$0"
],
"description": "#include \"\""
}
,"include-system": {
View optional-call-avoidance.swift
// Swift Ver. 3.0.1 (Release)
// Platform: Linux (x86_64)
// Noodling with syntax for call avoidance with optional arguments
// Just to get a sense of what it could look like
// Given a function "fn" that takes 2 non-optional arguments
// We can enable this syntax:
// let result = fn<-?(a, b)
// where a and b are optionals
View voice-data.js
[
[10, "en-US", "F", "" , "Ava" , "com.apple.ttsbundle.Ava-premium"],
[10, "en-US", "F", "Siri", "Nicky" , "com.apple.ttsbundle.siri_female_en-US_premium"],
[10, "en-US", "F", "" , "Allison" , "com.apple.ttsbundle.Allison-premium"],
[10, "en-US", "F", "" , "Susan" , "com.apple.ttsbundle.Susan-premium"],
[10, "en-US", "F", "" , "Samantha" , "com.apple.ttsbundle.Samantha-premium"],
[10, "en-US", "M", "Siri", "Aaron" , "com.apple.ttsbundle.siri_male_en-US_premium"],
[10, "en-US", "M", "" , "Tom" , "com.apple.ttsbundle.Tom-premium"],
[10, "en-GB", "F", "" , "Serena" , "com.apple.ttsbundle.Serena-premium"],
[10, "en-GB", "F", "" , "Kate" , "com.apple.ttsbundle.Kate-premium"],
View splatting.swift
let t = (1, 2, 3) // Anonymous tuple
let n = (x: 1, y: 2, z: 3) // Named tuple
func fn(_ a : Int, _ b : Int, _ c : Int) { // Separate params
print(a, b, c)
}
func tfn(_ t: (a : Int, b : Int, c : Int)) { // Single param
print(t.a, t.b, t.c)
}
View access-control.swift
//////////////////////
// File 1
public class Base {
public struct Overridable { // Do not store
private init() {}
}
public struct Protected { // OK to store
View misc-objective-cpp.mm
template <class T>
inline T* as(NSObject* o) {
if ([o isKindOfClass: [T class]]) {
return (T*)o;
}
return nil;
}
template <class T>
inline bool is(NSObject* o) {
View any-equal.swift
// Dynamic cast without bridging
func dynamicCast<T>(_ type: T.Type, _ v: Any)->T? {
guard let result = v as? T where v.dynamicType is T.Type else {
return nil;
}
return result
}
// Return a 2uple if both objects are convertible to type T, otherwise nil
func matchCast<T>(_ type: T.Type, _ l: Any, _ r: Any)->(T, T)? {
View simple-code-gen.swift
// Code generation!
let props = ["name", "value", "thing"]
for prop in props {
print([
"if local.\(prop) != remote.\(prop) {",
" local.\(prop) = remote.\(prop)",
" changes[\(prop)Key] = remote.\(prop)",
"}",
View responder-chain.swift
// This is just some noodling based on Brent's interest in Swift responder chains: http://inessential.com/2016/05/15/a_hypothetical_responder_chain_written_i
// Just showing that responder chain can easily fit with the level of dynamism in Swift today
infix operator >>> { associativity left }
func >>> <In, Middle, Out>(first: In -> Middle, second: Middle -> Out) -> In -> Out {
return { x in second(first(x)) }
}
func >>> <In, Out>(deduce: In.Type, fn: In -> Out) -> In -> Out {
View osx-jxa-javascript-basics.js
"use strict";
ObjC.import('Foundation');
var fm = $.NSFileManager.defaultManager;
var app = Application.currentApplication();
app.includeStandardAdditions = true;
var path = $.NSString.alloc.initWithUTF8String(app.pathTo(this)).stringByDeletingLastPathComponent.js + "/";
You can’t perform that action at this time.