Skip to content

Instantly share code, notes, and snippets.

View chhib's full-sized avatar

David Jurelius chhib

View GitHub Profile
@possibilities
possibilities / meteor-async.md
Created August 23, 2012 22:53
Meteor Async Guide

From Meteor's documentation:

In Meteor, your server code runs in a single thread per request, not in the asynchronous callback style typical of Node. We find the linear execution model a better fit for the typical server code in a Meteor application.

This guide serves as a mini-tour of tools, trix and patterns that can be used to run async code in Meteor.

Basic async

Sometimes we need to run async code in Meteor.methods. For this we create a Future to block until the async code has finished. This pattern can be seen all over Meteor's own codebase:

@tamoyal
tamoyal / gist:10441108
Created April 11, 2014 04:39
Create super user and database user in Mongo 2.6
# Create your superuser
$ mongo
> use admin
> db.createUser({user:"someadmin",pwd:"secret", roles:[{role:"root",db:"admin"}]})
> exit
# Alias for convenience (optional and at your own risk)
$ echo 'alias mongo="mongo --port 27017 -u someadmin -p secret --authenticationDatabase admin"' >> ~/.bash_profile
$ source ~/.bash_profile
@rex-lin
rex-lin / iOS Retention - BigQuery - (Tableau)
Last active October 27, 2017 04:55
iOS Retention - BigQuery - (Tableau)
SELECT
a.date,
'iOS' AS platform,
COUNT(DISTINCT a.fullVisitorId) AS day0,
COUNT(DISTINCT CASE WHEN a.date = date_add(b.date, INTERVAL -1 DAY) THEN b.fullVisitorId ELSE NULL END) AS day1,
COUNT(DISTINCT CASE WHEN a.date = date_add(b.date, INTERVAL -7 DAY) THEN b.fullVisitorId ELSE NULL END) AS day7,
COUNT(DISTINCT CASE WHEN a.date = date_add(b.date, INTERVAL -14 DAY) THEN b.fullVisitorId ELSE NULL END) AS day14,
COUNT(DISTINCT CASE WHEN a.date = date_add(b.date, INTERVAL -30 DAY) THEN b.fullVisitorId ELSE NULL END) AS day30,
COUNT(DISTINCT CASE WHEN a.date = date_add(b.date, INTERVAL -60 DAY) THEN b.fullVisitorId ELSE NULL END) AS day60,
COUNT(DISTINCT CASE WHEN a.date = date_add(b.date, INTERVAL -90 DAY) THEN b.fullVisitorId ELSE NULL END) AS day90
@rex-lin
rex-lin / iOS Unbounded - All Time
Last active January 12, 2017 14:41
iOS Unbounded - All Time
SELECT
a.date,
'iOS' AS platform,
COUNT(DISTINCT a.fullVisitorId) AS day0,
COUNT(DISTINCT CASE WHEN a.date <= date_add(b.date, INTERVAL -1 DAY) THEN b.fullVisitorId ELSE NULL END) AS day1,
COUNT(DISTINCT CASE WHEN a.date <= date_add(b.date, INTERVAL -7 DAY) THEN b.fullVisitorId ELSE NULL END) AS day7,
COUNT(DISTINCT CASE WHEN a.date <= date_add(b.date, INTERVAL -14 DAY) THEN b.fullVisitorId ELSE NULL END) AS day14,
COUNT(DISTINCT CASE WHEN a.date <= date_add(b.date, INTERVAL -30 DAY) THEN b.fullVisitorId ELSE NULL END) AS day30,
COUNT(DISTINCT CASE WHEN a.date <= date_add(b.date, INTERVAL -40 DAY) THEN b.fullVisitorId ELSE NULL END) AS day40,
COUNT(DISTINCT CASE WHEN a.date <= date_add(b.date, INTERVAL -50 DAY) THEN b.fullVisitorId ELSE NULL END) AS day50,
const sleep = ms => { return new Promise(resolve => setTimeout(resolve, ms)) }
const injectButton = async () => {
// Similiarly, we also need to wait for the page to load in...
await sleep(1000);
console.log("hey");
const {url} = await fetch("https://bhchiang--get-url-get.modal.run/").then(r => r.json());
const URL = `${url}/get_prompt`;
@markrittman
markrittman / ga4_attribution.sql
Created May 9, 2023 10:37
GA4 Multi-Step, Multi-Cycle Marketing Attribution example using the BigQuery GA4 Sample Dataset at https://developers.google.com/analytics/bigquery/web-ecommerce-demo-dataset
WITH
events AS (
SELECT
TIMESTAMP_MICROS(event_timestamp) AS event_ts,
CONCAT(user_pseudo_id,'-',event_name,'-',CAST(event_timestamp AS STRING)) AS event_id,
user_pseudo_id AS user_pseudo_id,
user_id,
traffic_source.name AS utm_channel,
traffic_source.medium AS utm_medium,
traffic_source.source AS utm_source,