Skip to content

Instantly share code, notes, and snippets.

View dineshba's full-sized avatar
👨‍💻
Trying to be an OSS contributor

Dinesh B dineshba

👨‍💻
Trying to be an OSS contributor
View GitHub Profile
@dineshba
dineshba / RLE.ex
Last active April 18, 2016 10:06
Run Length Encoding to understand pattern matching and recursion in Elixir
#Hi
#Lets try to solve the Run Length encoding problem. (Refer Run length encoding here https://en.wikipedia.org/wiki/Run-length_encoding)
#[1,1,2,3,3,3,4] => (Run Length Encoder)RLE => [{1,2},2,{3,3},4]
#For sake of simplicity, will try to solve like this [1,1,2,3,3,3,4] => RLE => [{1,2},{2, 1},{3,3},{4, 1}] and will optimize it finally.
#Lets try to solve incrementally
#[] => RLE => []
defmodule RunLengthEncoder do
def encode([]), do: []
interface SpinnerOptions {
lines?: number; // The number of lines to draw
length?: number; // The length of each line
width?: number; // The line thickness
radius?: number; // The radius of the inner circle
corners?: number; // Corner roundness (0..1)
rotate?: number; // The rotation offset
direction?: number; // 1: clockwise, -1: counterclockwise
color?: any; // #rgb or #rrggbb or array of colors
speed?: number; // Rounds per second
# Path to your oh-my-zsh installation.
export ZSH=~/.oh-my-zsh
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
ZSH_THEME="agnoster"
#ZSH_THEME="ys"
# Uncomment the following line to use case-sensitive completion.
" Use Vim settings, rather then Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible
set hlsearch
set incsearch
" ================ General Config ====================
colorscheme default
set number "Line numbers are good
set backspace=indent,eol,start "Allow backspace in insert mode
set history=1000 "Store lots of :cmdline history
[github]
user = dineshba
[user]
name = Dinesh Balasubramanian
email = dineshudt17@gmail.com
[core]
pager = less -FRX
#editor = atom --wait
editor = vi
autocrlf = input
# vim:ft=zsh ts=2 sw=2 sts=2
#
# agnoster's Theme - https://gist.github.com/3712874
# A Powerline-inspired theme for ZSH
#
# # README
#
# In order for this theme to render correctly, you will need a
# [Powerline-patched font](https://gist.github.com/1595572).
#
class MockAPIService: APIServiceProtocol {
var completeClosure: ((Bool, [Photo], APIError?) -> ())!
var photos: [Photo] = []
var error: APIError?
func fetchPopularPhoto(complete: @escaping (Bool, [Photo], APIError?) -> ()) {
isFetchPopularPhotoCalled = true
complete(error == nil, photos, error)
}
}
func test_fetch_photo_fail() {
// Given a failed fetch with a certain failure
mockAPIService.error = APIError.permissionDenied
// When
sut.initFetch()
// Sut should display predefined error message
XCTAssertEqual( sut.alertMessage, error.rawValue )
protocol Eatable {
var taste: Taste
func isBitter() -> Bool // No arg function syntax:
} // func functionName() -> ReturnType
struct Dog {
var name: String
var weight: Int
}
var myDog = Dog(name: "Ranger", weight: 10)
var yourDog = myDog //Deep copy
yourDog.name = "Puncher"
print(myDog) // Dog(name: "Ranger", weight: 10)
print(yourDog) // Dog(name: "Puncher", weight: 10)