Skip to content

Instantly share code, notes, and snippets.

View mr5z's full-sized avatar
🎯
Focusing

mark mr5z

🎯
Focusing
View GitHub Profile
@mr5z
mr5z / a.cs
Last active September 11, 2017 06:15
loop to linq
var a = response.Data
.Select(dto => Mapper.Map<SafeZoneDTO, SafeZone>(dto))
.Select(safeZone => safeZone.Points)
.Select(model => new SafeZonePosition {
Latitude = model.Latitude,
Longitude = model.Longitude,
SafeZoneId = safeZone.Id
});
foreach (var dto in response.Data) {
@mr5z
mr5z / constructor_signature.cs
Last active September 14, 2017 07:59
how to elegantly refactor this?
public SelectLocationMapViewModel(UserWithSafeZonesModel selectedUser,
bool enableLocationCountValidation,
IWebRequestManager webRequestManager,
IAccountService accountService,
IFollowMeService followMeService,
ILocationService locationService,
IDestinationService destinationService,
IKeyboardService keyboardService) :
this(null,
@mr5z
mr5z / a.cs
Last active September 21, 2017 06:33
create everything in linq
var filterByName = !string.IsNullOrEmpty(command.Search);
var friendList = (await repository.GetByFriendStatusAsync(FriendStatus.AlreadyFriend))
.Where(e => command.FriendTypes.Contains(e.FriendType))
.Take(command.PageSize);
if (filterByName) {
userFriends.Data = friendList.Where(e => e.FullName.Contains(command.Search)).ToList();
}
@mr5z
mr5z / a.cs
Created October 6, 2017 03:46
void LocationChanged(object sender, PositionEventArgs e)
{
if (stopWatch == null) {
stopWatch = Stopwatch.StartNew();
}
var position = e.Position;
if (UnixTimeStamp > previousUpdateTime + MinUpdateTime) {
stopWatch.Stop();
Log("location: ({0}, {1}), lapsed time: {2}", position.Latitude, position.Longitude, stopWatch.ElapsedMilliseconds);
previousUpdateTime = UnixTimeStamp;
@Query("SELECT id, title, description, dateCreated, certificateLink, deliveryStatus, userId\n" +
"FROM Certificates\n" +
"WHERE userId = :userId\n" +
"ORDER BY expirationDate")
List<CertificateDto> getAllNotifications(long userId);
@Query("SELECT id, title, description, dateCreated, certificateLink, deliveryStatus, userId\n" +
"FROM Certificates\n" +
"WHERE userId = :userId AND\n" +
" expirationDate <= date('now', '+8 hour') AND -- TODO: get client timezone from header\n" +
@mr5z
mr5z / room-dto.java
Last active November 14, 2017 18:22
@Entity(tableName = "Certificates",
foreignKeys = @ForeignKey(
entity = UserDto.class,
parentColumns = "id",
childColumns = "userId",
onUpdate = ForeignKey.SET_NULL,
onDelete = ForeignKey.SET_NULL))
public class CertificateDto {
@PrimaryKey
{
"formatVersion": 1,
"database": {
"version": 1,
"identityHash": "f0cd29d11d4a03881fedffb2c12feb23",
"entities": [
{
"tableName": "Certificates",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `userId` INTEGER NOT NULL, `title` TEXT, `description` TEXT, `dateCreated` TEXT, `expirationDate` TEXT, `certificateLink` TEXT, `deliveryStatus` INTEGER, PRIMARY KEY(`id`), FOREIGN KEY(`userId`) REFERENCES `Users`(`id`) ON UPDATE SET NULL ON DELETE SET NULL )",
"fields": [
@mr5z
mr5z / a.json
Created December 2, 2017 03:48
{
"status": "success/error",
"data": object/array
}
@mr5z
mr5z / a.cs
Last active December 19, 2017 08:25
spot what is wrong with this
class Test {
CancellationTokenSource cts;
async void DoSomething() {
var i = 0;
while (i < 10) {
i = i + 1;
public class PermissionGroup : ObservableCollection<Permission>
{
string _groupName;
public string GroupName {
get => _groupName;
set => SetPropertyChanged(ref _groupName, value);
}
public PermissionGroup(string groupName)
{
GroupName = groupName;