Skip to content

Instantly share code, notes, and snippets.

View dai-shi's full-sized avatar

Daishi Kato dai-shi

View GitHub Profile
@dai-shi
dai-shi / benchmark-startswith.js
Created February 14, 2013 03:51
benchmark of String.startsWith equivalents in Node.js
var Benchmark = require('benchmark');
Benchmark.prototype.setup = function() {
a = ["test"];
for (var i = 0; i < 10000; i++) {
a.push("some other stuff");
}
s = a.join();
re1 = new RegExp("^test");
re2 = new RegExp("^not there");
};
@dai-shi
dai-shi / dot2excalidraw.js
Last active April 17, 2021 14:31
dot2exalidraw experiment
const path = require('path');
const dot = require(path.resolve(process.argv[2]));
const output = {
"type": "excalidraw",
"version": 2,
"source": "https://excalidraw.com",
"elements": [],
@dai-shi
dai-shi / express-stream-react.js
Last active July 20, 2019 13:42
Infinite counter stream with express
const { Readable } = require('stream');
const express = require('express');
const createCounterReader = (delay) => {
let counter = 0;
const reader = new Readable({
read() {},
});
setInterval(() => {
counter += 1;
#!/usr/bin/env node
const electronInstaller = require('electron-winstaller');
(async () => {
try {
const options = JSON.parse(process.env.OPTIONS || process.argv[process.argv.length - 1]);
await electronInstaller.createWindowsInstaller(options);
} catch (e) {
console.error(e);
}
})();
@dai-shi
dai-shi / facebook-node-sdk-sample.js
Created April 22, 2013 13:33
A sample code to get an application access token using Thuzi / facebook-node-sdk.
var FB = require('fb');
FB.api('oauth/access_token', {
client_id: process.env.FACEBOOK_APP_ID,
client_secret: process.env.FACEBOOK_SECRET,
grant_type: 'client_credentials'
}, function(res) {
if (!res || res.error) {
console.log('error occurred when getting access token:', res && res.error);
return;
diff --git a/imports/api/tasks.tests.js b/imports/api/tasks.tests.js
index 1359e85..9b61c5a 100644
--- a/imports/api/tasks.tests.js
+++ b/imports/api/tasks.tests.js
@@ -2,6 +2,7 @@
import { Meteor } from 'meteor/meteor';
import { Random } from 'meteor/random';
+import { assert } from 'meteor/practicalmeteor:chai';
diff --git a/imports/api/tasks.tests.js b/imports/api/tasks.tests.js
index 05287ba..1359e85 100644
--- a/imports/api/tasks.tests.js
+++ b/imports/api/tasks.tests.js
@@ -1,10 +1,26 @@
/* eslint-env mocha */
import { Meteor } from 'meteor/meteor';
+import { Random } from 'meteor/random';
+
diff --git a/imports/api/tasks.js b/imports/api/tasks.js
index 441feee..9d5b56a 100644
--- a/imports/api/tasks.js
+++ b/imports/api/tasks.js
@@ -36,12 +36,24 @@ Meteor.methods({
'tasks.remove'(taskId) {
check(taskId, String);
+ const task = Tasks.findOne(taskId);
+ if (task.private && task.owner !== Meteor.userId()) {
diff --git a/imports/api/tasks.js b/imports/api/tasks.js
index f1d2c92..441feee 100644
--- a/imports/api/tasks.js
+++ b/imports/api/tasks.js
@@ -6,8 +6,14 @@ export const Tasks = new Mongo.Collection('tasks');
if (Meteor.isServer) {
// This code only runs on the server
+ // Only publish tasks that are public or belong to the current user
Meteor.publish('tasks', function tasksPublication() {
diff --git a/imports/ui/Task.jsx b/imports/ui/Task.jsx
index db0999e..52450c3 100644
--- a/imports/ui/Task.jsx
+++ b/imports/ui/Task.jsx
@@ -1,5 +1,6 @@
import React, { Component, PropTypes } from 'react';
import { Meteor } from 'meteor/meteor';
+import classnames from 'classnames';
// Task component - represents a single todo item