Skip to content

Instantly share code, notes, and snippets.

# Simulation of https://fivethirtyeight.com/features/can-you-survive-squid-game-riddler/
from random import randint
import statistics
times = 100000
data = []
# bridge made up of 18 pairs of separated glass squares.
BRIDGE_SQUARES = 18
BAD_GLASS = 1
@pgk
pgk / .gitignore
Last active May 30, 2019 21:19
Converts ATOM to RSS
# <genignore python>
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
import os
import sys
import json
import requests
from dotenv import load_dotenv
load_dotenv()
argv = sys.argv[1:]
@pgk
pgk / README.md
Last active February 15, 2019 12:49
Used for forked voronoi thing

txt

@pgk
pgk / sensei_show_learner_lessons_by_status_and_course.sql
Created December 5, 2017 12:12
Sensei: Show Lessons for a Learner by completion status. Also show quiz grade
-- Sensei: Show Lessons for a Learner by completion status. Also show quiz grade
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
use <your-database>;
SET @course_id = <your-course-id>;
SET @user_id = <your-user-id>;
SELECT c.comment_ID, c.user_id, c.comment_post_ID, cm.*
# From calculation, it is expected that the local minimum occurs at x=9/4
cur_x = 6 # The algorithm starts at x=6
gamma = 0.01 # step size multiplier
precision = 0.00001
previous_step_size = cur_x
df = lambda x: 4 * x**3 - 9 * x**2
while previous_step_size > precision:
@pgk
pgk / sensei_learner_stati.sql
Created October 11, 2017 09:20
Sensei: Show specific course/lesson status report for a learner
-- Sensei: Show specific course/lesson status report for a learner
--
-- Substitute table names and user id to match your setup
SELECT u.ID, COUNT(c.comment_type) AS `cnt`, c.comment_type AS `status_type`, c.comment_approved AS `status`
FROM `wp_users` AS u
JOIN `wp_comments` AS c ON u.ID = c.user_id
WHERE
c.comment_type IN ('sensei_course_status', 'sensei_lesson_status') AND
u.ID = 1
@pgk
pgk / wpjm_add_custom_field.php
Created June 22, 2017 16:45
WordPress Rest API: Adding custom fields to custom post types
<?php
/**
* Register a custom field (using a bit of Mixtape)
*
* @throws WPJM_REST_Exception When bad things happen.
*/
function register_job_listing_custom_fields() {
$env = $this->wpjm_rest_api->environment();
$string_type = $env->type()->definition( 'string' );
@pgk
pgk / euclidean_rhythm.py
Last active June 13, 2017 21:06
Euclidean Rhythm in vanilla py3
# Euclidean Rhythm in vanilla py3
def euclidean_rhythm(beats, pulses):
"""Computes Euclidean rhythm of beats/pulses
Examples:
euclidean_rhythm(8, 5) -> [1, 0, 1, 0, 1, 0, 1, 1]
euclidean_rhythm(7, 3) -> [1, 0, 0, 1, 0, 1, 0]
Args:
@pgk
pgk / sensei_cpt_course_do_not_use_with_front.php
Last active March 14, 2017 14:30
sensei_cpt_course_do_not_use_with_front.php
<?php
/*
* Plugin Name: Enable Sensei courses to display on /course
* Plugin URI:
* Description: Enable Sensei courses to display on /course/<course_name> instead of /blog/course/<course_name>,
* Author: WooThemes
* Author URI: https://woocommerce.com
* Requires at least: 4.7.3
* Tested up to: 4.7.3
* Domain path: /lang/