Skip to content

Instantly share code, notes, and snippets.

View nsomar's full-sized avatar

Omar Abdelhafith nsomar

View GitHub Profile
@nsomar
nsomar / counter-class.swift
Created September 24, 2016 00:13
Implementing a counter as a class
// Impelentation Counter as a class
class Counter {
private var x: Int
init(number: Int) {
x = number
}
func setNumber(_ number: Int) {
x = number
@nsomar
nsomar / sign.sh
Created January 25, 2017 10:51
Sign an ipa on travis
#!/bin/sh
# Create a custom keychain
security create-keychain -p travis ios-build.keychain
# Make the custom keychain default, so xcodebuild will use it for signing
security default-keychain -s ios-build.keychain
# Unlock the keychain
security unlock-keychain -p travis ios-build.keychain
defmodule Storage do
def start(initial) do
process = spawn_link(fn -> execute(initial) end)
Process.register(process, Storage)
process
end
def execute(state) do
receive do
> Storage.start([0])
> Storage.put(1)
> Storage.put(2)
> Storage.get() |> IO.inspect
[0, 1, 2]
# Creating
Agent.start_link(fn -> [0] end, name: Storage)
# Update
Agent.update(Storage, fn state -> state ++ [1] end)
Agent.update(Storage, fn state -> state ++ [2] end)
# Retreive
Agent.get(Storage, fn state -> state end) |> IO.inspect
defmodule Utilities do
def write(content, file) do
# write stuff to disk
# takes long time
end
end
defmodule Website do
def index(conn, content) do
# some calculations
defmodule Utilities do
def write(content, file) do
spawn(fn ->
# write stuff to disk
# takes long time
end)
end
end
> Utilities.write(content, file) |> IO.inspect
#PID<0.256.0>
defmodule Utilities do
def write(content, file) do
# get th target process
target = self()
spawn(fn ->
# write stuff to disk
# takes long time
defmodule Website do
def index(conn, content) do
# some calculations
Utilities.write(content, "/etc/some/secret/location")
# Receving the sent message
receive do
result -> # use the result
end