Skip to content

Instantly share code, notes, and snippets.

View Naereen's full-sized avatar
📝
Coder in long holidays - full time teacher

Lilian Besson Naereen

📝
Coder in long holidays - full time teacher
View GitHub Profile
@dmmfll
dmmfll / embed.py
Last active September 21, 2017 09:37
function for embedding a YouTube video into a Jupyter notebook. Be sure to use the url in the html from the embed share tab in YouTube.
"""Embed a YouTube video via its embed url into a notebook."""
from functools import partial
from IPython.display import display, IFrame
width, height = (560, 315, )
def _iframe_attrs(embed_url):
"""Get IFrame args."""
return (
@benhoyt
benhoyt / thread_test.py
Created November 3, 2016 13:53
Test how many threads we can run at once
"""Test how many threads we can run at once."""
import itertools
import threading
import time
import sys
import requests
@jagrosh
jagrosh / Github Webhook Tutorial.md
Last active June 7, 2024 04:59
Simple Github -> Discord webhook

Step 1 - Make a Discord Webhook

  1. Find the Discord channel in which you would like to send commits and other updates

  2. In the settings for that channel, find the Webhooks option and create a new webhook. Note: Do NOT give this URL out to the public. Anyone or service can post messages to this channel, without even needing to be in the server. Keep it safe! WebhookDiscord

Step 2 - Set up the webhook on Github

  1. Navigate to your repository on Github, and open the Settings Settings
@roycoding
roycoding / slots.md
Last active July 1, 2022 15:29
slots - A multi-armed bandit library in Python

Multi-armed banditry in Python with slots

Roy Keyes

22 Aug 2016 - This is a post on my blog.

I recently released slots, a Python library that implements multi-armed bandit strategies. If that sounds like something that won't put you to sleep, then please pip install slots and read on.

Some one armed bandits

Multi-armed bandits

@benhoyt
benhoyt / snakes_and_ladders.py
Last active May 20, 2018 09:02
Calculate the average number of moves in a snakes and ladders game
"""Calculate the average number of moves in a snakes and ladders game.
Because as a parent one gets roped into these board (boring?) games
every so often, and I wanted to calculate the average duration of a
snakes and ladders game. Turns out it's about 36 moves (though
admittedly that's for a single-player game). :-)
> python snakes_and_ladders.py
Played 10000 rounds, averaged 36.0559 moves, max 324 moves, took 0.508s
"""
@benhoyt
benhoyt / birthday_probability.py
Created August 5, 2016 18:27
"Birthday problem" calculator in Python
"""Calculate the probability of generating a duplicate random number after
generating "n" random numbers in the range "d".
Usage: python birthday_probability.py n [d=365]
Each value can either be an integer directly, or in the format "2**x", where
x is the number of bits in the value.
For example, to calculate the probability that two people will have the same
birthday in a room with 23 people:
@sorenbouma
sorenbouma / cem.py
Last active April 17, 2018 05:54
This is a basic python implementation of the Cross-Entropy Method for reinforcement learning on OpenAI gym's CartPole environment.
import gym
import numpy as np
import matplotlib.pyplot as plt
env = gym.make('CartPole-v0')
env.render(close=True)
#vector of means(mu) and standard dev(sigma) for each paramater
mu=np.random.uniform(size=state.shape)
sigma=np.random.uniform(low=0.001,size=state.shape)
@benhoyt
benhoyt / ngrams.py
Created May 12, 2016 15:34
Print most frequent N-grams in given file
"""Print most frequent N-grams in given file.
Usage: python ngrams.py filename
Problem description: Build a tool which receives a corpus of text,
analyses it and reports the top 10 most frequent bigrams, trigrams,
four-grams (i.e. most frequently occurring two, three and four word
consecutive combinations).
NOTES
@Naereen
Naereen / bh_core.sublime-settings
Last active February 6, 2016 00:28
Custom brackets for LaTeX+ for the BracketHighlighter Sublime Text 3 plugin
{
// Custom brackets for LaTeX+ for the BracketHighlighter Sublime Text 3 plugin
// Needs the LaTeX+ plugin from https://github.com/randy3k/Latex-Plus/
// And the BracketHighlighter plugin from https://github.com/facelessuser/BracketHighlighter
// Based on this page https://github.com/randy3k/Latex-Plus/wiki/BracketHighlighter-settings
//
// HowTo use: save this to Packages/User/bh_core.sublime-settings
// (or Menu > Preferences > Package Settings > BracketHighlighter > Brackets Settings - User)
//
// FIXME reorder the objects in a more logical fashion
@jepio
jepio / minted.py
Last active September 18, 2023 13:58
Pandoc filter to use minted for syntax highlighting
#!/usr/bin/env python3
'''
Filter to wrap Pandoc's CodeBlocks into minted blocks when using latex.
Pandoc's `fence_code_attributes` can be used to provide:
- the language (first class)
- minted's argumentless options (following classes)
- minted's options with arguments (attributes)
'''