Skip to content

Instantly share code, notes, and snippets.

View Dev1an's full-sized avatar

Damiaan Dufaux Dev1an

View GitHub Profile
@Dev1an
Dev1an / addedFiles.sh
Created October 5, 2015 08:12
Show a list of files that were added in the latest commit
git diff @{1} --name-only --diff-filter=A
@Dev1an
Dev1an / Timestamps in radix 36.md
Last active November 21, 2015 13:15
This gist shows you how to encode the current time into raidx 36 strings using Javascript

##Encoding current time

  (new Date).getTime().toString(36)

##Decoding milliseconds in radix into a date

  new Date(parseInt("radixDate", 36))
@Dev1an
Dev1an / Easy NSLayoutConstraints.swift
Last active February 19, 2018 23:17
An easy way to create layout constraints with some custom swift operators.
//
// ConstraintOperators.swift
//
// Created by Damiaan Dufaux on 10/12/15.
// Copyright © 2015 Damiaan Dufaux. All rights reserved.
//
import Foundation
import UIKit
meteor mongo domain.com --url
mongodump -u username -p password --host production-db-c1.meteor.io --port 27017 -d database
ffmpeg -y -r 30 -f image2pipe -vcodec ppm -i ./scene.ppm -vcodec libx264 -pix_fmt yuv420p -f mov -preset fast -crf 2 -threads 0 ./scene.mov
source /opt/ros/indigo/setup.bash
@Dev1an
Dev1an / csv.swift
Created November 3, 2016 17:43
import CSV in swift
public protocol CommaSeparatedValueCompatible {
init(values: [String]) throws
}
public func arrayFromCSV<Record: CommaSeparatedValueCompatible>(at file: URL, lineSeparator: String = "\n", columnSeparator: String = ",") throws -> [Record] {
let lines = try String(contentsOf: file).trimmingCharacters(in: CharacterSet(charactersIn: lineSeparator)).components(separatedBy: lineSeparator)
return try lines.dropFirst().map { line in
return try Record(values: line.components(separatedBy: columnSeparator))
}
}
@Dev1an
Dev1an / SortedArray.swift
Last active November 5, 2016 12:21
A sorted array in swift
//
// SortedArray.swift
//
// Created by Damiaan on 05-11-16.
// Copyright © 2016 Damiaan. All rights reserved.
//
import Foundation
public struct SortedArray<Element>: RandomAccessCollection, Collection {
function highlight(highlightedElement) {
var restore = []
const oldRadius = highlightedElement.style.borderRadius
const oldShadow = highlightedElement.style.boxShadow
restore.push(() => {highlightedElement.style.borderRadius = oldRadius; highlightedElement.style.boxShadow = oldShadow})
highlightedElement.style.borderRadius = "1px"
highlightedElement.style.boxShadow = "0 0 0 4px white , 2px 2px 10px 4px rgba(0, 0, 0, 0.39)"
const timer = setTimeout(function() {
@Dev1an
Dev1an / Predicates.swift
Last active June 8, 2017 15:32
Generic predicates (in Swift 4)
extension Sequence {
func find<Property, Argument>(where predicate: (propertyPath: KeyPath<Self.Element, Property>, comparator: (Property, Argument)->Bool, argument: Argument)) -> [Self.Element] {
return filter { predicate.comparator($0[keyPath: predicate.propertyPath], predicate.argument) }
}
// A more specialised version:
func find(where characteristic: KeyPath<Self.Element, Bool>) -> [Self.Element] {
return filter { $0[keyPath: characteristic] }
}
}