Skip to content

Instantly share code, notes, and snippets.

@ryanspradlin
ryanspradlin / brent.js
Last active March 20, 2024 06:48
Javascript implementation of Brent's Method, a root-finding algorithm
/* @flow */
// Derived from: https://en.wikipedia.org/wiki/Brent%27s_method#Algorithm
// Brent's method is a hybrid root-finding algorithm that combines the
// faster/less-reliable inverse quadradic interpolation and secant methods with
// the slower/more-reliable bisection method.
export function brent(
f: (x: number) => number,
lowerBound: number,
@ryanlintott
ryanlintott / NoClipText.swift
Last active August 20, 2021 02:40
Alternative Text view for SwiftUI with an extendable clipping area. This is a fix for certain fonts and characters that have a clipped intrinsic size.
import SwiftUI
import UIKit
struct NoClipText: UIViewRepresentable {
typealias UIViewType = NoClipLabel
let text: String
let font: UIFont
let clipExtension: EdgeSizes
@mjrulesamrat
mjrulesamrat / countryinfo.py
Created July 14, 2016 09:33 — forked from pamelafox/countryinfo.py
Python list of country codes, names, continents, capitals, and pytz timezones
countries = [
{'timezones': ['Europe/Andorra'], 'code': 'AD', 'continent': 'Europe', 'name': 'Andorra', 'capital': 'Andorra la Vella'},
{'timezones': ['Asia/Kabul'], 'code': 'AF', 'continent': 'Asia', 'name': 'Afghanistan', 'capital': 'Kabul'},
{'timezones': ['America/Antigua'], 'code': 'AG', 'continent': 'North America', 'name': 'Antigua and Barbuda', 'capital': "St. John's"},
{'timezones': ['Europe/Tirane'], 'code': 'AL', 'continent': 'Europe', 'name': 'Albania', 'capital': 'Tirana'},
{'timezones': ['Asia/Yerevan'], 'code': 'AM', 'continent': 'Asia', 'name': 'Armenia', 'capital': 'Yerevan'},
{'timezones': ['Africa/Luanda'], 'code': 'AO', 'continent': 'Africa', 'name': 'Angola', 'capital': 'Luanda'},
{'timezones': ['America/Argentina/Buenos_Aires', 'America/Argentina/Cordoba', 'America/Argentina/Jujuy', 'America/Argentina/Tucuman', 'America/Argentina/Catamarca', 'America/Argentina/La_Rioja', 'America/Argentina/San_Juan', 'America/Argentina/Mendoza', 'America/Argentina/Rio_Gallegos', 'America/Argentina/Ushuai
@jerheff
jerheff / binary_crossentropy_with_ranking.py
Created January 9, 2016 01:08
Experimental binary cross entropy with ranking loss function
def binary_crossentropy_with_ranking(y_true, y_pred):
""" Trying to combine ranking loss with numeric precision"""
# first get the log loss like normal
logloss = K.mean(K.binary_crossentropy(y_pred, y_true), axis=-1)
# next, build a rank loss
# clip the probabilities to keep stability
y_pred_clipped = K.clip(y_pred, K.epsilon(), 1-K.epsilon())
@rogiervandenberg
rogiervandenberg / JourneyExtractor.php
Last active March 1, 2024 11:51
Journal (by Journey) extractor. Journey is a great Diary app for Android and Google Chrome. But, your files are only accessible by Journey itself. Do you want to move away from Journey to another diary app? Do you want to have a readable export of your diary? This script converts Journey backup/export files to managable Markdown files. One file …
<?php
/*
Journal (by Journey) extractor
Journey is a great Diary app for Android and Google Chrome. But, your files are
only accessible by Journey itself.
Do you want to move away from Journey to another diary app? Do you want to have
a readable export of your diary? This script converts Journey backup/export
@adamlj
adamlj / send_mailgun_attachments.py
Created January 23, 2014 10:53
MailGun API Python Requests multiple Attachments Send mail with multiple files/attachments with custom file names
requests.post("https://api.mailgun.net/v2/DOMAIN/messages",
auth=("api", "key-SECRET"),
files={
"attachment[0]": ("FileName1.ext", open(FILE_PATH_1, 'rb')),
"attachment[1]": ("FileName2.ext", open(FILE_PATH_2, 'rb'))
},
data={"from": "FROM_EMAIL",
"to": [TO_EMAIL],
"subject": SUBJECT,
"html": HTML_CONTENT