Skip to content

Instantly share code, notes, and snippets.

Avatar

Anojh Gnanachandran agnanachandran

View GitHub Profile
@agnanachandran
agnanachandran / notifications_store_test.ts
Created Feb 15, 2018
tests/notifications_store_test.ts
View 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 Feb 15, 2018
tests/notifications_view_container_test.tsx
View 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 Feb 15, 2018
views/notifications_view.tsx
View 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 Feb 15, 2018
views/notifications_view_container.tsx
View 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 Feb 15, 2018
stores/root_store.ts
View 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 Feb 15, 2018
stores/notifications_store.ts
View 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 Feb 15, 2018
models/notification.ts
View notification.ts
class Notification {
@observable read: boolean;
constructor(
public id: string,
public content: string,
public time: number,
read: boolean
) {
this.read = read;
View houses.py
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]
You can’t perform that action at this time.