Skip to content

Instantly share code, notes, and snippets.

const SECRET_KEY = ENTER YOUR SECRET KEY HERE;
const MAX_TOKENS = 200;
// For more cool AI snippets and demos, follow me on Twitter: https://twitter.com/_abi_
/**
* Completes your prompt with GPT-3
*
* @param {string} prompt Prompt
* @param {number} temperature (Optional) Temperature. 1 is super creative while 0 is very exact and precise. Defaults to 0.4.
@markrittman
markrittman / ten_next_pageviews_after_landing_page.sql
Created May 29, 2022 22:43
Return first ten page views after landing on a particular page using Segment
with events as (
select
anonymous_id,
user_id,
cast(null as string) as name,
cast(null as string) as email,
timestamp,
'page_view' as event_type,
concat(split(context_ip,'.')[safe_offset(0)],'.***.***.',split(context_ip,'.')[safe_offset(3)]) as context_ip,
context_page_path,
@markrittman
markrittman / landing_page_user_paths.sql
Last active December 30, 2022 10:23
Most common user paths from a given landing page
with events as (
select
anonymous_id,
user_id,
cast(null as string) as name,
cast(null as string) as email,
timestamp,
'page_view' as event_type,
concat(split(context_ip,'.')[safe_offset(0)],'.***.***.',split(context_ip,'.')[safe_offset(3)]) as context_ip,
context_page_path,
@lewish
lewish / sessionized_segment_data.sql
Last active April 25, 2024 19:41
Sessionized segment tracks & pages (BigQuery)
/*
This query creates a combined view of tracks and pages from segment data.
Sessions are computed by finding the any session start timestamp denoted by an activity gap of 30 minutes.
Session IDs are assigned to each track or page record using a combination of the session index, user ID, and date.
*/
WITH
with_session_starts AS (
SELECT
*,
COALESCE( (UNIX_MILLIS(timestamp) - UNIX_MILLIS(LAG(timestamp) OVER (PARTITION BY user_id ORDER BY timestamp ASC)))/(1000*60) >= 30,
@mguezuraga
mguezuraga / AESCipher.py
Last active February 24, 2020 23:16 — forked from swinton/AESCipher.py
Encrypt & Decrypt using PyCrypto AES 256From http://stackoverflow.com/a/12525165/119849
#!/usr/bin/env python
import base64
from Crypto import Random
from Crypto.Cipher import AES
BS = 16
pad = lambda s: s + (BS - len(s) % BS) * chr(BS - len(s) % BS)
unpad = lambda s : s[0:-s[-1]]
@morganherlocker
morganherlocker / index.js
Last active May 3, 2016 20:21
tile-reduce + cheap-ruler example
var tileReduce = require('tile-reduce');
var path = require('path');
tileReduce({
zoom: 14,
map: path.join(__dirname, '/process.js'),
sources: [
{name: 'ways', mbtiles: 'ways.mbtiles')}
]
});
@iandees
iandees / install.md
Last active January 31, 2018 09:57
Installing and running Project OSRM, the OpenStreetMap-based routing engine, on an Amazon EC2 instance.

My goal here was the create a routable graph for Chicago.

I used Ubuntu 12.04LTS on an m2.4xlarge just to be sure memory wasn't too much of an issue.

Install

Start a screen session and start downloading an OSM extract (I used this extract of Illinois). In another screen I did the following:

  sudo apt-get update && sudo apt-get upgrade -y

sudo apt-get -y install git make cmake build-essential \

@JamesChevalier
JamesChevalier / osmosis_on_digitalocean.sh
Created February 8, 2014 00:13
My complete process of generating OSMs from POLYs on DigitalOcean servers
# Server
apt-get update
apt-get install -y python-software-properties
add-apt-repository -y ppa:webupd8team/java
apt-get update
apt-get install -y oracle-java7-installer sysstat convmv ruby1.9.3
wget http://bretth.dev.openstreetmap.org/osmosis-build/osmosis-latest.tgz
mkdir osmosis
tar -xvzf osmosis-latest.tgz -C osmosis
chmod a+x osmosis/bin/osmosis
@tomatohater
tomatohater / parsehar.py
Last active October 26, 2023 10:30
parsehar.py - Reads a har file from the filesystem, converts to CSV, then dumps to stdout.
"""Reads a har file from the filesystem, converts to CSV, then dumps to
stdout.
"""
import argparse
import json
from urlparse import urlparse
def main(harfile_path):
"""Reads a har file from the filesystem, converts to CSV, then dumps to
@swinton
swinton / AESCipher.py
Last active April 30, 2023 05:48
Encrypt & Decrypt using PyCrypto AES 256 From http://stackoverflow.com/a/12525165/119849
#!/usr/bin/env python
import base64
from Crypto import Random
from Crypto.Cipher import AES
BS = 16
pad = lambda s: s + (BS - len(s) % BS) * chr(BS - len(s) % BS)
unpad = lambda s : s[0:-ord(s[-1])]