Skip to content

Instantly share code, notes, and snippets.

@masters3d
masters3d / default.swift
Created June 20, 2019 17:09
Default Init for Swift 5.0
protocol Initializable {
init()
}
extension String:Initializable {}
struct Default<T> where T:Initializable {
typealias SomeType = T
static func some() -> SomeType {
return SomeType()
}
@masters3d
masters3d / std::optional.md
Last active July 29, 2018 03:42
Write up on the C++11 optional feature.

std::optional

I chose the new C++17 feature called [std::optional]. I am attracted to this feature because I am a big fan of the [optional type in Swift] and others languages like TypeScript and C#. The main idea behind optional is that is meant to address the fact that not all types are meant to be null. Languages like [Rust and Swift] (which market themselves as the next C++ killer) emerged around 2010-2015 already with the idea of optionals from the get-go.

#include "stdafx.h"
#include <optional>
#include <string>
#include <iostream>
using System;
using System.Collections.Generic;
using System.Linq;
namespace n_queen
{
class Program
{
static int gridSize = 4;
@masters3d
masters3d / swift.bash
Created June 23, 2018 05:53
switch macos default swift
sudo xcode-select --switch /Applications/Xcode-10bA.app/
export TOOLCHAINS=swift
@masters3d
masters3d / size_of_folders.sh
Created June 13, 2018 22:24
Get the size of subfolders in the current dir
du -h --max-depth=1 --block-size=G . | sort -n
; Author: fwompner gmail com
#InstallKeybdHook
SetCapsLockState, alwaysoff
Capslock::
Send {LAlt Down}
KeyWait, CapsLock, T9 ; added timeout
Send {LAlt Up}
if ( instr(A_PriorKey, "Capslock") )
{
Send {Alt}
export SQL_BACKUP_JOB_ID="${SQL_BACKUP_JOB_ID:-$SQL_BACKUP_JOB_ID_CI}" # Check if we set the Job ID variable if not use the default
@masters3d
masters3d / DataController.js
Created July 30, 2017 01:58
This code saves a loads data from the localStorage object on the browser.
'use strict';
class DataController {
}
DataController.load = loadLocalStorage
DataController.save = saveLocalStorage
function loadLocalStorage() {
let rawData = localStorage.getItem('masters3d');
if which swiftlint >/dev/null; then
cd ..
echo "Local Linting Dir"
echo $PWD
if [ "$CI" = true ]; then
swiftlint
else
swiftlint lint
swiftlint autocorrect --format
fi
@masters3d
masters3d / json_storage.js
Created June 21, 2017 21:08 — forked from emanb29/json_storage.js
Getters and setters for localStorage allowing it to transparently store objects using es6's Proxy
/* json_storage.js
* @danott
* 26 APR 2011
*
* Building on a thread from Stack Overflow, override localStorage and sessionStorage's
* getter and setter functions to allow for storing objects and arrays.
*
* Original thread:
* http://stackoverflow.com/questions/2010892/storing-objects-in-html5-localstorage
*