Skip to content

Instantly share code, notes, and snippets.

View panw's full-sized avatar

Pan W panw

  • New York, New York
View GitHub Profile
@panw
panw / WeeklyUserRetentionRate.js
Last active August 29, 2015 14:02
Calculate weekly user retention rate using array arithmetic
var weeklyRetention = new Array(); // For storing weekly retntion rate
// Unique user sessions grouped by week
var sessions = [{week: 1, ids: [1, 2, 19, 33]}, {week: 2, ids: [5, 2, 19, 33, 55, 88]},....]
// Loop until second to last element of the array
var i = 0;
while(i < sessions.length-1) {
var usersStartOfPeriod = sessions[i].ids;
var usersEndOfPeriod = sessions[i+1].ids;
@panw
panw / grocery_list1.html
Last active August 29, 2015 14:04
Template with pre-filled hard coded list for rendering and making sure things work.
<head>
<title>Grocery List</title>
</head>
<body>
{{> groceryList}}
</body>
<template name="groceryList">
Items = new Meteor.Collection('items');
if(Meteor.isClient()){
Template.groceryList.helpers({
items: function() {
return Items.find();
}
});
}
<head>
<title>Grocery List</title>
</head>
<body>
<!-- render template name groceryList -->
{{> groceryList}}
</body>
<!-- define template name groceryList -->
@panw
panw / grocery_list2.js
Created August 1, 2014 05:23
For part 4 of the tutorial. Updated code so users could check off items from the list.
Items = new Meteor.Collection('items');
if(Meteor.isClient){
Template.groceryList.events({
'click li' : function(event, template){
var listItem = event.currentTarget; // get the list item being clicked on
$('#'+listItem.id).hide(); // hide li with matching id
// update check attribute for the item in the database
Items.update(listItem.id, { $set : {checked:true} }, function(error){
@panw
panw / grocery_list3.html
Last active August 29, 2015 14:04
For Part 5 of the tutorial. Added an input field and add button to give users the functionality to add items to the list.
<head>
<title>Grocery List</title>
</head>
<body>
<!-- render template name groceryList -->
{{> groceryList}}
</body>
<!-- define template name groceryList -->
@panw
panw / grocery_list3.js
Created August 1, 2014 06:00
For part 5 of the tutorial. Code was added to give users the functionality to add items to the list.
Items = new Meteor.Collection('items');
if(Meteor.isClient){
Template.groceryList.events({
'click li' : function(event, template){
var listItem = event.currentTarget; // get the list item being clicked on
$('#'+listItem.id).hide(); // hide li with matching id
// update check attribute for the item in the database
Items.update(listItem.id, { $set : {checked:true} }, function(error){
function Dog() {
this.name = "Lassie";
this.greeting = "woof";
this.greet = function() {
console.log(this.name, "says", this.greeting);
};
this.eat = function() {
console.log(this.name, "is eating");
@panw
panw / react-intro-starter.html
Created March 27, 2016 01:10
Starter code for React Intro session
<!-- index.html -->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>React Tutorial</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.7/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.7/react-dom.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.min.js"></script>
</head>
class Gumball
attr_reader :color, :flavor
DEFAULT_COLORS = ['red', 'green', 'blue']
DEFAULT_FLAVORS = ['sour apple', 'bacon', 'gravy']
def initialize(options={})
@color = options.fetch(:color) { DEFAULT_COLORS.sample }
@flavor = options.fetch(:flavor) { DEFAULT_FLAVORS.sample }
end
end