Skip to content

Instantly share code, notes, and snippets.

View alexandru-calinoiu's full-sized avatar
💭
Crafting

Calinoiu Alexandru Nicolae alexandru-calinoiu

💭
Crafting
View GitHub Profile
class UserAddressBook
attr_accessor :user_id, :address_book_entry
def initialize(user_id, address_book_entry)
@user_id = user_id
@address_book_entry = address_book_entry
end
end
address_book1 = UserAddressBook.new(42, 'test')
@alexandru-calinoiu
alexandru-calinoiu / matchers.rb
Created November 7, 2016 15:25
Play around with dry matchers
require 'dry-matcher'
success_case = Dry::Matcher::Case.new(
match: -> value { value.first == :ok },
resolve: -> value { value.last }
)
failure_case = Dry::Matcher::Case.new(
match: -> value, *pattern {
value[0] == :err && (pattern.any? ? pattern.include?(value[1]) : true)
@alexandru-calinoiu
alexandru-calinoiu / dry-monads.rb
Created November 6, 2016 03:10
Play around with dry monads.
require 'dry-monads'
class Address
attr_reader :street
def initialize(street = nil)
@street = street
end
end
@alexandru-calinoiu
alexandru-calinoiu / custom_case.rb
Last active September 29, 2016 14:17
Playing with ruby case
class Success
def self.===(item)
item.status >= 200 && item.status < 300
end
end
class Empty
def self.===(item)
item.response_size == 0
end
@alexandru-calinoiu
alexandru-calinoiu / observable.rb
Created July 26, 2016 11:17
Some notes about observables based on a blog entry
require 'observer'
class Source
include Observable
def ping(int)
changed
notify_observers(int)
end
end
@alexandru-calinoiu
alexandru-calinoiu / UserProfileView.xaml
Last active August 29, 2015 14:26
Add the list of devices in the second row
<Border Grid.Row="1" Style="{DynamicResource ListScreenContainerStyle}"
BorderThickness="{DynamicResource ListBorderThickness}">
<ListView SelectionMode="Single"
ItemsSource="{Binding Path=Devices, Mode=OneWay}"
Style="{StaticResource VirtualisedMetroListView}"
BorderThickness="0">
<ListView.ItemTemplate>
<DataTemplate>
<ContentControl cal:View.Model="{Binding}" />
</DataTemplate>
<Grid HorizontalAlignment="Left" Style="{DynamicResource MasterListContainerStyle}">
<Grid.RowDefinitions>
<RowDefinition Height="todo" />
<RowDefinition Height="todo" />
</Grid.RowDefinitions>
</Grid>
@alexandru-calinoiu
alexandru-calinoiu / SessionInfo.xaml
Last active August 29, 2015 14:26
Solution for adding a button
<Button>
<Button.Template>
<ControlTemplate>
<Control Style="{DynamicResource SideUserImageStyle}" Tag="{Binding Path=User.Image}" />
</ControlTemplate>
</Button.Template>
</Button>
@alexandru-calinoiu
alexandru-calinoiu / gist:451bb7cdaa1e67111ae7
Last active January 29, 2022 05:04
Send a CURL get request with an array param
This took me longer that I will like to find out
curl "http://localhost:3000/v1/collections/42/items?fields[]=synopsis" -v -H "Content-Type: application/json" -H "X-Session-Token: xxx" --globoff
Laptop laptop = Laptop.new
laptop.listener = KeyBoardListener.new
class KeyBoardListener
def key_press(key_code)
...
end
end