Skip to content

Instantly share code, notes, and snippets.

@MilenPavlov
MilenPavlov / tsql find intersection between two dates
Created March 4, 2014 09:58
find intersection between two dates:
SELECT DISTINCT EHS.EmployeeID, MAX(CASE WHEN FromDate >= @DateFrom THEN FromDate ELSE @DateFrom END) AS Starts,
MAX(CASE WHEN ToDate <= @DateTo THEN ToDate ELSE @DateTo END) AS Ends, E.Salaried, ISNULL(E.Salary, 0) as Salary
FROM EmployeeHolidaySickness EHS
LEFT OUTER JOIN Employees E ON EHS.EmployeeID = E.EmployeeID
WHERE (RecordType = 'H') AND (FromDate <= @DateTo AND ToDate >= @DateFrom)
GROUP BY EHS.EmployeeID, E.Salaried, ISNULL(E.Salary, 0)
@MilenPavlov
MilenPavlov / gist:98e210e3ffe1fbe4ecd9
Last active September 14, 2020 10:42
ContentObserver for Xamarin Android Photos using MediaStore.IntentActionStillImageCamera
//PhotoObserver.cs
public class Media
{
public System.DateTime Added { get; set; }
public File File { get; set; }
public System.DateTime Modified { get; set; }
public string Type { get; set; }
public override string ToString()
@MilenPavlov
MilenPavlov / gist:84fb89e04f735c90874c
Created April 9, 2015 08:08
Using new async Google Maps in Xamarin Android
//_mapFragment.Map is now obsolete with latest Google Play services.. new approach is needed...
private void SetUpMap()
{
_mapFragment = FragmentManager.FindFragmentByTag("map") as MapFragment;
if (_mapFragment == null)
{
GoogleMapOptions mapOptions = new GoogleMapOptions()
.InvokeMapType(GoogleMap.MapTypeHybrid)
.InvokeZoomControlsEnabled(true)
.InvokeCompassEnabled(true);
@MilenPavlov
MilenPavlov / gist:fd89529b3e6224484a1b
Created April 15, 2015 08:45
email regex (rfc compliant)
email regex:
[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?
usage:
bool isEmail = Regex.IsMatch(emailString, @"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z", RegexOptions.IgnoreCase);
@MilenPavlov
MilenPavlov / gist:63b49cdac893fdaa73c4
Created April 16, 2015 08:24
Horizontal ScrollView for (Xamarin) Android using RecyclerView and GridLayoutManager
//MainActivity's private vars and key methods:
public class MainActivity : FragmentActivityBase
{
private RecyclerView _recyclerViewPhotosTakenEdit;
private IList<PhotoItemModel> _photoItemsModel;
private RecyclerView.LayoutManager _layoutManager;
private PhotoQuestionRecyclerAdapter _photoQuestionImageAdapter;
......
}
@MilenPavlov
MilenPavlov / gist:493c26952da76bec4b87
Created May 12, 2015 09:44
SavePhotoToAppDirectory
private void SavePhotoToAppDirectory(NSData data)
{
var documentsDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
var jpgFilename = System.IO.Path.Combine(documentsDirectory,
$"Photo{DateTime.Now.TimeOfDay.Milliseconds}.jpg");
if (File.Exists(jpgFilename)) return;
NSError err = null;
if (!data.Save(jpgFilename, false, out err))
@MilenPavlov
MilenPavlov / gist:a73a401d6299c02cc329
Last active July 19, 2017 09:14
Xamarin iOS – Create custom TreeView control for iPad / iPhone
This example uses Storyboards and iPad app. We have few entities here the TreeViewController (also holding the TreeViewSource delegate and my TreeNode Class) and TreeViewCell where I’m adding UIViews programatically.
Code as follows:
1) TreeViewController class:
public partial class TvViewController : UIViewController
{
public TvViewController(IntPtr handle) : base(handle)
@MilenPavlov
MilenPavlov / mvvmexample.txt
Created September 10, 2015 08:15
mvvm command usage complete example
//the command:
private RelayCommand logInCommand;
public RelayCommand LogInCommand
{
get
{
return logInCommand ??
(logInCommand = new RelayCommand(
@MilenPavlov
MilenPavlov / basicTemplate.json
Created November 13, 2015 15:05
ARM Template for TaskLogger
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"siteName": { "type": "string" },
"siteLocation": {
"type": "string",
"defaultValue": "West Europe"
},
"sqlServerName": {
@MilenPavlov
MilenPavlov / armtemplate.json
Created December 7, 2015 11:44
arm template
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"baseUriName": {
"type": "string"
},
"sqlServerName": {
"type": "string"
},