Skip to content

Instantly share code, notes, and snippets.

View begimai's full-sized avatar

Begimai Amantaeva begimai

  • Bishkek, Kyrgyzstan
View GitHub Profile
@zbyte64
zbyte64 / events.py
Created November 1, 2020 18:33
Example: Django-Graphene subscriptions with graphene_subscriptions and django_lifecycle
from enum import Enum, auto
class NotificationEvents(Enum):
NEW_MESSAGE = auto()
UPDATE_MESSAGE = auto()
@minorbug
minorbug / timeago.swift
Created November 7, 2014 15:28
"Time ago" function for Swift (based on MatthewYork's DateTools for Objective-C)
func timeAgoSinceDate(date:NSDate, numericDates:Bool) -> String {
let calendar = NSCalendar.currentCalendar()
let unitFlags = NSCalendarUnit.CalendarUnitMinute | NSCalendarUnit.CalendarUnitHour | NSCalendarUnit.CalendarUnitDay | NSCalendarUnit.CalendarUnitWeekOfYear | NSCalendarUnit.CalendarUnitMonth | NSCalendarUnit.CalendarUnitYear | NSCalendarUnit.CalendarUnitSecond
let now = NSDate()
let earliest = now.earlierDate(date)
let latest = (earliest == now) ? date : now
let components:NSDateComponents = calendar.components(unitFlags, fromDate: earliest, toDate: latest, options: nil)
if (components.year >= 2) {
return "\(components.year) years ago"