Skip to content

Instantly share code, notes, and snippets.

View SimplGy's full-sized avatar

Eric Miller SimplGy

View GitHub Profile

No Runtime Error:

func == (l: Car, r: Car) -> Bool { return l.vin == r.vin }
struct Car { let vin: String }
protocol hasDriversLicense: class {
  var car: Car? { get set }
}
class YoungPro: hasDriversLicense {
@SimplGy
SimplGy / most-beautiful-js-ever.js
Last active September 13, 2016 05:09
A collection of weepingly beautiful javascript written by other people. For me to open late at night and admire secretly.
// Pull a secret string out of ordered triplets
// https://www.codewars.com/kata/recover-a-secret-string-from-random-triplets/train/javascript
// https://www.codewars.com/kata/53f40dff5f9d31b813000774/solutions/javascript
// @LesRamer
var recoverSecret = function(triplets) {
for(var [first] of triplets)
{
if (triplets.every(tuple => tuple.indexOf(first) <= 0))
{
@SimplGy
SimplGy / Animate.swift
Last active October 27, 2016 19:29
A starter animation library for swift. These abstractions make it easier to chain multiple behaviors (eg: anticpate, then slam, then fade) because you can use them as single liners and reason only about the actions. Usage: `Animate.show.bySpringing.fromAbove(alert)`
import Foundation
/*
A starter animation library for swift.
These abstractions make it easier to chain multiple behaviors (eg: anticpate, then slam, then fade)
because you can use them as single liners and reason only about the actions.
Usage:
@SimplGy
SimplGy / renameToHash.sh
Last active July 27, 2023 07:30
Rename files with a hash based on their contents. eg: `abc.jpg` to `3101ace8db9f.jpg`. Useful for detecting duplicates.
#!/bin/bash
# TODO: skip tiny files (so small they couldn't be photos)
# TODO: make sure sym links and other file system oddities are handled
# TODO: look at paralellization for perf boost
#
# Constants
#
CHAR_COUNT=12
BLOCK_COUNT=6
@SimplGy
SimplGy / shades-and-lights.scss
Created January 22, 2018 19:57
Utility colors for SCSS
// Lights (white as a transparency)
$light10: rgba(255, 255, 255, 0.10);
$light20: rgba(255, 255, 255, 0.20);
$light30: rgba(255, 255, 255, 0.30);
$light40: rgba(255, 255, 255, 0.40);
$light50: rgba(255, 255, 255, 0.50);
$light60: rgba(255, 255, 255, 0.60);
$light70: rgba(255, 255, 255, 0.70);
$light80: rgba(255, 255, 255, 0.80);
@SimplGy
SimplGy / keymap.cson
Created April 15, 2018 17:24
IntelliJ style keybindings for the Atom text editor
'atom-text-editor':
'cmd-backspace': 'editor:delete-line'
'cmd-up': 'editor:move-line-up'
'cmd-down': 'editor:move-line-down'
'cmd-d': 'editor:duplicate-lines'
@Injectable({providedIn: 'root'})
export class ExternalUrlService implements CanActivate {
canActivate({ data }: ActivatedRouteSnapshot): boolean {
window.open(data.externalUrl, '_blank');
return false;
}
}
@SimplGy
SimplGy / count-dom-words.js
Last active November 5, 2018 04:54
This counts up all the words (innerText) at each level of the dom tree.
// Procedure:
countWords(document.body);
/*
* Count the text inside each element.
* Parents include all the words of their children.
@SimplGy
SimplGy / keybindings.json
Created November 11, 2018 05:02
VSCode keybindings
// Place your key bindings in this file to overwrite the defaults
[
{
"key": "cmd+d",
"command": "editor.action.copyLinesDownAction",
"when": "editorTextFocus && !editorReadonly"
},
{
"key": "shift+alt+down",
"command": "-editor.action.copyLinesDownAction",
@SimplGy
SimplGy / sort-object-keys.ts
Last active March 16, 2019 21:53
sort keys of an object using an array index as rank, with TypeScript
export interface SomeShape {
b: string,
c: string,
a: string,
}
// Specify your sort order here
const rank: Array<keyof SomeShape> = ['a', 'b', 'c'];
export function sortedKvpString(obj: SomeShape) {