Skip to content

Instantly share code, notes, and snippets.

View agnanachandran's full-sized avatar

Anojh Gnanachandran agnanachandran

  • Heap
  • New York, NY
View GitHub Profile
@agnanachandran
agnanachandran / notifications_store_test.ts
Created February 15, 2018 21:50
tests/notifications_store_test.ts
describe('Notifications Store', () => {
it('should have read and unread notifications', () => {
const readNotification = new Notification('1', 'read', 100, true);
const unreadNotification = new Notification('2', 'unread', 101, false);
const unreadNotification2 = new Notification('3', 'unread2', 102, false);
const notifications = [readNotification, unreadNotification, unreadNotification2];
const notificationsStore = NotificationsStore.initialize(notifications);
expect(notificationsStore.unreadNotifications).to.have.length(2);
@agnanachandran
agnanachandran / notifications_view_container_test.tsx
Created February 15, 2018 21:49
tests/notifications_view_container_test.tsx
describe('NotificationsViewContainer', () => {
it('should render NotificationsView', () => {
const readNotification = new Notification('1', 'read', 100, true);
const unreadNotification = new Notification('2', 'unread', 101, false);
const unreadNotification2 = new Notification('3', 'unread2', 102, false);
const notifications = [readNotification, unreadNotification, unreadNotification2];
const notificationsStore = NotificationsStore.initialize(notifications);
const wrapper = mount(
<NotificationsViewContainer
@agnanachandran
agnanachandran / notifications_view.tsx
Created February 15, 2018 21:48
views/notifications_view.tsx
interface NotificationsViewProps {
unreadNotifications: Notification[];
readNotifications: Notification[];
onMarkAsRead: (notification: Notification) => void;
}
class NotificationsView extends React.Component<NotificationsViewProps, {}> {
render(): JSX.Element {
return (
<div>
@agnanachandran
agnanachandran / notifications_view_container.tsx
Created February 15, 2018 21:44
views/notifications_view_container.tsx
interface NotificationsViewContainerProps {
notificationsStore: NotificationsStore;
}
@observer
class NotificationsViewContainer extends React.Component<NotificationsViewContainerProps, {}> {
render(): JSX.Element {
return (
<NotificationsView
readNotifications={ this.props.notificationsStore.readNotifications }
@agnanachandran
agnanachandran / root_store.ts
Last active February 15, 2018 21:38
stores/root_store.ts
class RootStore {
notificationsStore: NotificationsStore;
initialize(): void {
// Retrieve initial state of notifications
const notifications: Notification[] = ...
this.notificationsStore = NotificationsStore.initialize(notifications);
}
}
@agnanachandran
agnanachandran / notifications_store.ts
Last active February 15, 2018 22:03
stores/notifications_store.ts
class NotificationsStore {
@observable notificationsById: mobx.ObservableMap<Notification>;
static initialize(notifications: Notification[]): NotificationsStore {
const notificationsById = mobx.asMap(_.keyBy(notifications, 'id'));
return new NotificationsStore(notificationsById);
}
@computed get unreadNotifications(): Notification[] {
return _(this.notificationsById.values())
@agnanachandran
agnanachandran / notification.ts
Last active February 15, 2018 21:32
models/notification.ts
class Notification {
@observable read: boolean;
constructor(
public id: string,
public content: string,
public time: number,
read: boolean
) {
this.read = read;
import math
import random
def get_random_neighbour(state):
neighbour = [house[:] for house in state] # Deep copy
i, j = random.sample(xrange(5), 2)
attr_idx = random.randint(0, 4)
neighbour[i][attr_idx], neighbour[j][attr_idx] = neighbour[j][attr_idx], neighbour[i][attr_idx]