Skip to content

Instantly share code, notes, and snippets.

View luki's full-sized avatar

Lou Süsslin luki

View GitHub Profile
@luki
luki / latin.swift
Created April 5, 2016 14:44
Checks if typed in message contains a character that doesn't fit A-Z, 0-9 & _.
import Foundation
import UIKit
func unallowedCharacter(word: String, alert: Bool) -> AnyObject {
var arrayOfString = Array(word.characters)
var containsUnallowedCharacter = false
for i in 0...arrayOfString.count - 1 {
var currentCharacter: String = String(arrayOfString[i]).lowercaseString
@luki
luki / calculator-class.swift
Created April 5, 2016 14:46
A calculator class in Swift.
class Calculator {
let first: Double
let second: Double
init(first: Double, second: Double){
self.first = first
self.second = second
@luki
luki / ar.swift
Created November 12, 2016 23:04
Algorithm for random generation of hex colors & hex color palettes
import UIKit
/* Randomly choose if number of letter, then randomly give
back a value */
func randomCharacter() -> String? {
let numbers = [0,1,2,3,4,5,6, 7, 8, 9]
let letters = ["A","B","C","D","E","F"]
let numberOrLetter = arc4random_uniform(2)
@luki
luki / example.dart
Created November 12, 2016 23:15
Map of InputElement Query Selectors
import 'qsmap.dart';
// An example using the helper 'qsmap.dart'
void submitAction(MouseEvent event) {
List parameters = ["name", "email", "body"];
String name;
String email;
String body;
@luki
luki / class-exploring.swift
Created January 11, 2017 06:40
Used for comparing Swift to Rust
public class Human {
private var firstName: String?
private var lastName: String?
private var age: Int?
// INITIALIZERS
public init(_ firstName: String?, _ lastName: String?, _ age: Int?) {
self.firstName = firstName
self.lastName = lastName
@luki
luki / search.rs
Created August 8, 2017 11:28
Studying search algorithms, implementing them in Rust
fn linear_search<T: Ord>(vec: &Vec<T>, key: &T) -> Option<usize> {
let mut result: Option<usize> = None;
for (i, n) in vec.into_iter().enumerate() {
if n == key {
result = Some(i)
}
};
result
import Foundation
func executeOperation<A: Numeric>(_ op: @escaping (_ a: A, _ b: A) -> A) -> (_ n1: A, _ n2: A) -> A {
return { n1, n2 in
op(n1, n2)
}
}
func subtract(_ n1: Int, _ n2: Int) -> Int {
return n1 - n2
use std::collections::HashMap;
trait StringToF32 {
fn to_f32(self) -> f32;
}
impl StringToF32 for String {
fn to_f32(self) -> f32 {
self.parse::<f32>().unwrap()
}
@luki
luki / bidirectional-map.rs
Created November 2, 2017 14:23
A bidirectional map in Rust
use std::collections::HashMap;
use std::hash::Hash;
pub struct BidirectionalMap<K, V> {
right_to_left: HashMap<K, V>,
left_to_right: HashMap<V, K>
}
impl<K,V> BidirectionalMap<K, V>
where K: Hash + Eq + Clone,
@luki
luki / binary_search.swift
Created November 11, 2017 15:30
Binary Search Algorithm (Must be sorted!)
extension Int {
var asDouble: Double {
return Double(self)
}
}
extension Double {
var halve: Double {
return self / 2
}