Skip to content

Instantly share code, notes, and snippets.

View dkalamari's full-sized avatar

Dino Kalamari dkalamari

  • Međimurje IPC d.d.
  • Čakovec, Croatia
View GitHub Profile
@dkalamari
dkalamari / gist:5633231
Created May 23, 2013 07:13
WPF bind item command to parent
//WPF part
<ItemsControl ItemsSource="{Binding companyList}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<RadioButton Command="{Binding Path= DataContext.ChooseCompanyCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}}" CommandParameter="{Binding CompanyID}" GroupName="Company" Content="{Binding CompanyName}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
//ViewModel
@dkalamari
dkalamari / gist:5655665
Created May 27, 2013 07:39
Named arguments
void Method (int a = 0, int b = 0, int c = 0, int d = 0) { ... }
Method (d:3);
//a=0, b=0, c=0, d=3
@dkalamari
dkalamari / gist:5655740
Last active December 17, 2015 18:49
Enumerator yield
static IEnumerable<int> Fibs (int fibCount)
{
for (int i = 0, prevFib = 1, curFib = 1; i < fibCount; i++)
{
yield return prevFib;
int newFib = prevFib+curFib;
prevFib = curFib;
curFib = newFib;
}
}
@dkalamari
dkalamari / gist:5655784
Created May 27, 2013 08:14
Anonymous types
var actress = new { Name = "Rosario", Surname="Dawson", Age = 34 };
//OR
int Age= 34;
var actress = new { Name = "Rosario", Surname="Dawson", Age };
@dkalamari
dkalamari / gist:5660637
Last active December 17, 2015 19:29
MP3
GOOGLE: intitle:"index.of" (mp3) BAND_NAME -html -htm -php -jsp
BING: BAND_NAME contains:mp3 intitle:"index of"
@dkalamari
dkalamari / gist:5668150
Created May 29, 2013 05:22
Read file line by line
StreamReader reader = new StreamReader(PathToFile);
while (!reader.EndOfStream)
{
string line = reader.ReadLine();
}
@dkalamari
dkalamari / gist:5684651
Created May 31, 2013 12:24
MYSQL Get ID from Insert command
INSERT INTO user(mail, adress) VALUES('[email protected]','Unknown');
select LAST_INSERT_ID();
@dkalamari
dkalamari / gist:5684723
Created May 31, 2013 12:38
MYSQL Insert datetime format for inserting into table
DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")
@dkalamari
dkalamari / gist:5704297
Created June 4, 2013 07:53
WPF Button next to textbox
<DockPanel LastChildFill="True" Grid.Column="1" Grid.Row="1" Margin="0">
<Button ToolTip="Edit" DockPanel.Dock="Right" Width="Auto" Height="20" VerticalAlignment="Bottom" Content="Edit" Command="{Binding OpenTextEditorCommand}"/>
<TextBox DockPanel.Dock="Left" Width="Auto" MinHeight="60" MaxHeight="100" Text="{Binding Model.Text, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" HorizontalAlignment="Stretch" TextWrapping="Wrap" VerticalScrollBarVisibility="Visible" AcceptsReturn="True" ></TextBox>
</DockPanel>
@dkalamari
dkalamari / gist:5712421
Created June 5, 2013 08:24
Anonymous methods for events using lambda
window.Closing += (sender, args) => {
if(Model.CanSave)
if (MessageBox.Show("Save?", "Saving", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
Model.Save();
}
else
{
Model.Cancel();
}