Skip to content

Instantly share code, notes, and snippets.

@nokyotsu
nokyotsu / merge
Created March 24, 2014 13:54
merge two text files, highlight differences
diff old-file new-file --old-group-format='<<<<<<< .old
%<=======
' --new-group-format='=======
%>>>>>>>> .new
' --changed-group-format='<<<<<<< .old
%<=======
%>>>>>>>> .new
'
@nokyotsu
nokyotsu / bernouli-sample.py
Created December 10, 2013 05:41
Estimate the total number of successes while sampling from a Bernoulli distribution. See: <http://stats.stackexchange.com/q/78440/9845>
#!/usr/bin/env python3
import random
from operator import mul
from functools import reduce
from fractions import Fraction
def bin_prob(k, n, p_min=0.1, samples=99999):
alpha = k + 1
beta = n - k + 1
p_est = sum(1 for i in range(samples) if random.betavariate(alpha, beta) >= p_min)
\documentclass{beamer}
\let\svpar\par
\let\svitemize\itemize
\let\svenditemize\enditemize
\let\svitem\item
\def\newpar{\def\par{\svpar\vfill}}
\def\newitem{\def\item{\vfill\svitem}}
\let\svcenter\center
\let\svendcenter\endcenter
@nokyotsu
nokyotsu / PartialFormatter.py
Last active January 16, 2019 10:52
Gracefully format missing fields. Instead of throwing errors, “None” values and missing fields/attributes are formatted using a specified string. http://stackoverflow.com/q/20248355/359178
#!/usr/bin/env python3
import string
class PartialFormatter(string.Formatter):
def __init__(self, missing='~'):
self.missing = missing
def get_field(self, field_name, args, kwargs):
# Handle missing fields
try:
@nokyotsu
nokyotsu / example.tex
Created November 12, 2013 15:55
Beamer example
\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amssymb,amsfonts,latexsym}
\usepackage[T1]{fontenc}
\usepackage{beamerthemesplit}
\usepackage{latexsym}
\usepackage{eurosym}
\usepackage[spanish]{babel} % no necesita activeacute si usas utf8
\usepackage{ae,aecompl}
\usepackage{graphicx}
@nokyotsu
nokyotsu / kbd_tag.rb
Last active February 10, 2021 18:10
Jekyll liquid tag to easily type OSX style keyboard combinations.
# Turns:
# {% kbd shift cmd V %}
# Into:
# <kbd>⇧ shift</kbd><kbd>⌘ cmd</kbd><kbd>V</kbd>
module Jekyll
class Kbd < Liquid::Tag
def initialize(tag_name, markup, tokens)
@markup = markup
# http://meta.apple.stackexchange.com/q/193/68