Skip to content

Instantly share code, notes, and snippets.

SELECT
( week_0_cohort/week_0_cohort ) AS week_0,
( week_1_cohort/week_0_cohort ) AS week_1,
( week_2_cohort/week_0_cohort ) AS week_2,
( week_3_cohort/week_0_cohort ) AS week_3
FROM (
WITH week_0 AS(
SELECT DISTINCT user_pseudo_id
FROM `firebase-public-project.analytics_153293282.events_*`
WITH week_0 AS(
SELECT DISTINCT user_pseudo_id
FROM `firebase-public-project.analytics_153293282.events_*`
WHERE _TABLE_SUFFIX BETWEEN '20180731' AND '20180807'
),
week_1 AS (
SELECT DISTINCT user_pseudo_id
FROM `firebase-public-project.analytics_153293282.events_*`
JOIN base using(user_pseudo_id)
@andy51002000
andy51002000 / retention-week1.sql
Created April 6, 2020 13:14
week 1 of retention
WITH base AS(
SELECT DISTINCT user_pseudo_id
FROM `firebase-public-project.analytics_153293282.events_*`
WHERE _TABLE_SUFFIX BETWEEN '20180731' AND '20180807'
)
SELECT DISTINCT user_pseudo_id
FROM `firebase-public-project.analytics_153293282.events_*`
JOIN base using(user_pseudo_id)
WHERE _TABLE_SUFFIX BETWEEN '20180807' AND '201808015'
@andy51002000
andy51002000 / retention-get-usr.sql
Last active April 6, 2020 13:12
calculate retention: get all user
SELECT DISTINCT user_pseudo_id
FROM `firebase-public-project.analytics_153293282.events_*`
WHERE _TABLE_SUFFIX BETWEEN '20180731' AND '20180807'
@andy51002000
andy51002000 / publish.pubxml
Created December 22, 2019 08:52
.NET publish profile
<?xml version="1.0" encoding="utf-8"?>
<!--
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>MSDeploy</WebPublishMethod>
<ResourceId></ResourceId>
<ResourceGroup></ResourceGroup>
var query2 = from a in query1
group a by new { year = a.Timestamp.Year, month = a.Timestamp.Month, day = a.Timestamp.Day } into d
select new { dt = string.Format("{0}{1}{2}", d.Key.year, d.Key.Month, d.Key.day), count = d.Count };
var query1 = (from b in this.Context.Activities
where b.Timestamp > date.Item1
select b
).AsEnumerable()
@andy51002000
andy51002000 / IncorrectLINQ2EF_example.cs
Created November 16, 2019 07:45
Wrong LINQ Query example, LINQ to Entities does not recognize the method System.String Format
var result =
from a in this.Activities
where a.Timestamp > date.Item1
group a by new { year=a.Timestamp.Year, month=a.Timestamp.Month, day=a.Timestamp.Day } into d
select new { dt = string.Format("{0}{1}{2}", d.Key.year, d.Key.month, d.Key.day), count = d.Count}
;
@andy51002000
andy51002000 / MyAPIController.cs
Last active October 22, 2019 07:20
My API Controller that handler the request /my
public class MyApiController : ApiController
{
[HttpGet]
[Route("api/myapi/res")]
public IHttpActionResult GetResource1()
{
return Ok("Hello Andy: welcome to my site ");
}
}
@andy51002000
andy51002000 / Global.asax.cs
Last active October 22, 2019 07:31
ASP .NET MVC support web api and add message handler
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
GlobalConfiguration.Configure(WebApiConfig.Register);
GlobalConfiguration.Configuration.MessageHandlers.Add(new APIKeyMessageHandler());
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);