Skip to content

Instantly share code, notes, and snippets.

//The game of life in Swift
//I have a huge crush on this language, I wish I could do more with it
// I'm looking this stuff up in the iBook, which has hilariously
// consequences when trying to copy/paste code snippets
import Cocoa
import XCPlayground
//Ugh, coming from my last project in VanillaJS, having a sweet array constructor rules!!
require 'json'
string = { foo: 'bar', baz: { bill: 'bob' } }.to_json
def santize(string)
# Turn string into Hash or Array
result = JSON.parse(
string,
# This option lets us mutate strings
# By default strings are frozen
set nocompatible
syntax on
map <Esc> <Nop>
set nu
set mouse=a
execute pathogen#infect()
autocmd vimenter * if !argc() | NERDTree | endif
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
"====[ Make the 81st column stand out ]====================
@topher6345
topher6345 / flatten.rb
Created August 24, 2015 19:24
Monkey patch Array#flatten
class Array
def flatten
@result = []
_flatten(self)
end
private
def _flatten(collection)
collection.each do |item|
@topher6345
topher6345 / caesar_cipher.rb
Created August 6, 2015 18:43
A library for encoding/cracking the Ceasar Cipher
# A library for encoding/cracking the Ceasar Cipher
module CaesarCipher
ALPHABET = ('a'..'z').to_a
ALPHABET_UPCASE = ('A'..'Z').to_a
# Responsible for encrypting a string
# using the Caesar Cipher
class Encoder
attr_reader :encoded_message
def initialize(plaintext:, shift:)
@words = plaintext.split(' ')
@topher6345
topher6345 / seive_of_eratosthenes.swift
Created June 10, 2015 01:14
Seive of Eratosthenes
import Cocoa
enum Status {
case unmarked, prime, composite
}
class SeiveOfEratosthenes {
let ceiling: Int
let ceiling_sqrt: Int
var table = [Int: Status]()
@topher6345
topher6345 / seive_of_eratosthenes.rb
Last active August 29, 2015 14:22
Seive of Eratosthenes
# Naive implementation of the Seive of Eratosthenes
#
# # Usage
# SeiveOfEratosthenes.find_primes(10_000)
#
class SeiveOfEratosthenes
attr_reader :set_array
# Return an array of all prime numbers below ceiling
def self.find_primes(ceiling)
new(ceiling).mark_table.filter_table.set_array
@topher6345
topher6345 / caesar_cipher.rb
Last active August 29, 2015 14:22
Caesar Cipher
# A library for encoding/cracking the Ceasar Cipher
module CaesarCipher
ALPHABET = ('a'..'z').to_a
ALPHABET_UPCASE = ('A'..'Z').to_a
# Responsible for encrypting a string
# using the Caesar Cipher
class Encoder
attr_reader :encoded_message
def initialize(plaintext:, shift:)
@topher6345
topher6345 / dining_philosophers.rb
Last active August 29, 2015 14:18
Dining Philosophers
# Dining Philosophers
# \ # /
# # #
# /#|#\
#
# Philosophers
# \ 0 /
# 4 1
# /3|2\
#