Skip to content

Instantly share code, notes, and snippets.

@mahadirz
mahadirz / Finding User Sessions with SQL
Created February 13, 2020 02:51 — forked from bstancil/Finding User Sessions with SQL
These queries let you define find user sessions against event data logged to Segment SQL, Snowplow, or Google BigQuery.
-- These queries let you define find user sessions against event data
-- logged to Segment SQL, Snowplow, or Google BigQuery.
-- For more details, see the full post:
-- LINK
--- SEGMENT SQL
-- Finding the start of every session
SELECT *
FROM (
@mahadirz
mahadirz / web_traffic_sampling.php
Last active March 5, 2020 03:39
Web traffic allocation algorithm for A/B Test
<?php
/**
* @author Mahadir Ahmad
* http://madet.my
* Traffic Allocation Algorithm
*
*/
/**
* O(n) method of generating Binom(n,p) distributed random numbers
{
"item": {
"itemid": 5023009141,
"price_max_before_discount": -1,
"item_status": "normal",
"can_use_wholesale": false,
"show_free_shipping": false,
"estimated_days": 2,
"is_hot_sales": null,
"is_slash_price_item": false,
@mahadirz
mahadirz / sagemaker_pyspark.sh
Created September 17, 2020 04:07
sagemaker pyspark error
(python3) sh-4.2$ pyspark
Python 3.7.7 (default, Mar 26 2020, 15:48:22)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
Exception in thread "main" java.lang.ExceptionInInitializerError
at org.apache.spark.SparkConf$.<init>(SparkConf.scala:668)
at org.apache.spark.SparkConf$.<clinit>(SparkConf.scala)
at org.apache.spark.SparkConf$$anonfun$getOption$1.apply(SparkConf.scala:375)
at org.apache.spark.SparkConf$$anonfun$getOption$1.apply(SparkConf.scala:375)
at scala.Option.orElse(Option.scala:289)
http://www.oreilly.com/data/free/files/2014-data-science-salary-survey.pdf
http://www.oreilly.com/data/free/files/2015-data-science-salary-survey.pdf
http://www.oreilly.com/data/free/files/Data_Analytics_in_Sports.pdf
http://www.oreilly.com/data/free/files/advancing-procurement-analytics.pdf
http://www.oreilly.com/data/free/files/ai-and-medicine.pdf
http://www.oreilly.com/data/free/files/analyzing-data-in-the-internet-of-things.pdf
http://www.oreilly.com/data/free/files/analyzing-the-analyzers.pdf
http://www.oreilly.com/data/free/files/architecting-data-lakes.pdf
http://www.oreilly.com/data/free/files/being-a-data-skeptic.pdf
http://www.oreilly.com/data/free/files/big-data-analytics-emerging-architecture.pdf
@mahadirz
mahadirz / vagrant-cheat-sheet.md
Created April 24, 2021 14:55 — forked from wpscholar/vagrant-cheat-sheet.md
Vagrant Cheat Sheet

Typing vagrant from the command line will display a list of all available commands.

Be sure that you are in the same directory as the Vagrantfile when running these commands!

Creating a VM

  • vagrant init -- Initialize Vagrant with a Vagrantfile and ./.vagrant directory, using no specified base image. Before you can do vagrant up, you'll need to specify a base image in the Vagrantfile.
  • vagrant init <boxpath> -- Initialize Vagrant with a specific box. To find a box, go to the public Vagrant box catalog. When you find one you like, just replace it's name with boxpath. For example, vagrant init ubuntu/trusty64.

Starting a VM

  • vagrant up -- starts vagrant environment (also provisions only on the FIRST vagrant up)
@mahadirz
mahadirz / tun-ping-linux.py
Created October 28, 2021 09:19 — forked from glacjay/tun-ping-linux.py
Reading/writing Linux's TUN/TAP device using Python.
import fcntl
import os
import struct
import subprocess
# Some constants used to ioctl the device file. I got them by a simple C
# program.
TUNSETIFF = 0x400454ca
TUNSETOWNER = TUNSETIFF + 2
event <pymysqlreplication.row_event.UpdateRowsEvent object at 0x7f7a183cd358>
=== UpdateRowsEvent ===
Date: 2022-01-09T00:06:05
Log position: 18082707
Event size: 351
Read bytes: 17
Table: db_1.users
Affected columns: 22
Traceback (most recent call last):
File "b.py", line 106, in <module>
@mahadirz
mahadirz / binlog-raw.sh
Last active January 9, 2022 07:35
binlog-tutorial
mysqlbinlog \
--read-from-remote-server \
--host=mydatabase-test.ap-southeast-1.rds.amazonaws.com \
--port=3306 \
--user mahadir \
--password \
--database my_database_schema\
--raw\
--result-file=mysql-bin-changelog.009964 mysql-bin-changelog.009964
@mahadirz
mahadirz / mysql-binlog-decoded.sh
Created January 9, 2022 07:50
binlog-tutorial
mysqlbinlog mysql-bin-changelog.009964\
--base64-output=DECODE-ROWS \
--verbose > mysql-bin-changelog.009964.decoded.txt