Skip to content

Instantly share code, notes, and snippets.

@kayleg
kayleg / CircleLayoutExercise-Complete.swift
Created September 10, 2020 15:38
Base SwiftUI for CircleLayout exercise
// This is the completed Circle layout sample. Use CircleLayoutExercise.swift as a starting point if you want to try on your own.
import SwiftUI
struct MiniCircle : View {
var title: String
var body: some View {
Circle()
.strokeBorder(Color.white,lineWidth: 2)
.background(Circle().foregroundColor(Color.accentColor))
@kayleg
kayleg / connector.rs
Created May 16, 2018 04:26
Rust Android SSL Certs
use std::io::{Read, Write};
use std::ops::{Deref, DerefMut};
use dh::Dh;
use error::ErrorStack;
use pkey::PKeyRef;
use ssl::{
self, HandshakeError, Ssl, SslContext, SslContextBuilder, SslMethod, SslRef, SslStream,
SSL_VERIFY_PEER,
};
@kayleg
kayleg / fizzbuzz.cpp
Last active July 10, 2022 21:37
fizzbuzz without branching
#include <iostream>
int main(int argc, char *argv[])
{
// Buffer to store num converted to string
char empty[9];
memset(empty, 0, sizeof(empty));
// Lookup table
const char* table[16] = { empty, empty, empty, "fizz\0 ", empty,
--- a/modules/legacy/src/dpstereo.cpp
+++ b/modules/legacy/src/dpstereo.cpp
@@ -76,7 +76,7 @@ typedef struct _CvRightImData
uchar min_val, max_val;
} _CvRightImData;
-#define CV_IMAX3(a,b,c) ((temp3 = (a) >= (b) ? (a) : (b)),(temp3 >= (c) ? temp3 : (c)))
+#define CV_IMAX3(a,b,c) ((temp2 = (a) >= (b) ? (a) : (b)),(temp2 >= (c) ? temp2 : (c)))
#define CV_IMIN3(a,b,c) ((temp3 = (a) <= (b) ? (a) : (b)),(temp3 <= (c) ? temp3 : (c)))
@kayleg
kayleg / gist:5215127
Created March 21, 2013 17:54
Handlebars currency helper and test
Handlebars.registerHelper('currency', function(amount, options) {
if (typeof(amount) === 'string') { amount = options.contexts[0].get(amount); }
var rounded = Math.round(amount * 100);
var dec = rounded % 100;
var whole = rounded / 100 - dec / 100;
var decStr = '' + dec;
return '$' + whole + '.' + decStr + ( decStr.length < 2 ? '0' : '');
});
test("USD", function () {