Skip to content

Instantly share code, notes, and snippets.

@xleon
xleon / ExtendedSearchBarRenderer.cs
Created February 25, 2015 01:44
Xamarin.Forms renderer to hide the "Cancel" button of a SearchBar on iOS
using System;
using Xamarin.Forms.Platform.iOS;
using Xamarin.Forms;
using UIKit;
using System.Diagnostics;
[assembly: ExportRenderer(typeof(SearchBar), typeof(Namespace.iOS.Renderers.ExtendedSearchBarRenderer))]
namespace Namespace.iOS.Renderers
{
@xleon
xleon / SignalR_IntegrationTest.cs
Last active July 26, 2018 20:18
Attempt to test a SignalR (authorized) method (chat "SendMessage") in a one-to-one chat
[TestMethod]
public async Task SendMessage_Should_SaveData_AndReachPeer()
{
IHubProxy proxy1 = await CreateConnectionAndGetProxy(AdminToken);
IHubProxy proxy2 = await CreateConnectionAndGetProxy(UserToken);
ChatMessageDTO pushedMessage = new ChatMessageDTO();
proxy1.On<ChatMessageDTO>("AddNewMessage", m => pushedMessage = m);
ChatMessageEntryDTO message = new ChatMessageEntryDTO
@xleon
xleon / EFNestedCollections.cs
Last active August 29, 2015 14:15
Entity framework nested collection filtering
public async Task<IEnumerable<Conversation>> GetUserConversations(string userId)
{
var temp = await conversationRepo.GetDbSet()
.Where(x => x.DeletedBy != userId)
.Where(x => x.SellerId == userId || x.BuyerId == userId)
.Select(x => new
{
conversation = x,
buyer = x.Buyer,
seller = x.Seller,
@xleon
xleon / models.py
Created October 23, 2013 07:38
Next and prev models when using django-admin-sortable. This is useful for "next" and "prev" buttons of a project detail for example
from adminsortable.models import Sortable
from django.template.defaultfilters import slugify
class Project(Sortable):
name = models.CharField("Name", max_length=255)
slug = models.SlugField(max_length=255, editable=False)
def save(self, *args, **kwargs):
self.slug = slugify(self.name)
super(Project, self).save(*args, **kwargs)
@xleon
xleon / models.py
Last active December 26, 2015 07:18
When using easy_thumbnails on django you want to delete created thumbnails in two cases: 1) you update or "clean" the image file of the model 2) you delete the model instance. Using Signals, this is pretty easy This code is tested and working when updating one item, removing it and it also works when bulk deleting
from easy_thumbnails.models import Source, Thumbnail
from django.db import models
from django.db.models.signals import pre_delete, pre_save
from project_package import settings
class Project(models.Model):
name = models.CharField("Name", max_length=255)
main_image = models.ImageField("Main Image", blank=True, null=True, upload_to='uploads')
def __unicode__(self):