Attention: the list was moved to
https://github.com/dypsilon/frontend-dev-bookmarks
This page is not maintained anymore, please update your bookmarks.
import collections, random, sys, textwrap | |
# Build possibles table indexed by pair of prefix words (w1, w2) | |
w1 = w2 = '' | |
possibles = collections.defaultdict(list) | |
for line in sys.stdin: | |
for word in line.split(): | |
possibles[w1, w2].append(word) | |
w1, w2 = w2, word |
/** | |
* useScroll React custom hook | |
* Usage: | |
* const { scrollX, scrollY, scrollDirection } = useScroll(); | |
*/ | |
import { useState, useEffect } from "react"; | |
export function useScroll() { | |
const [lastScrollTop, setLastScrollTop] = useState(0); |
import Foundation | |
import UIKit | |
import WebKit | |
class ViewController: UIViewController, WKNavigationDelegate, WKUIDelegate { | |
var webView: WKWebView! | |
var activityIndicator: UIActivityIndicatorView! | |
@IBOutlet var webViewContainer: UIView! | |
def add_cors_headers(response): | |
response.headers['Access-Control-Allow-Origin'] = '*' | |
if request.method == 'OPTIONS': | |
response.headers['Access-Control-Allow-Methods'] = 'DELETE, GET, POST, PUT' | |
headers = request.headers.get('Access-Control-Request-Headers') | |
if headers: | |
response.headers['Access-Control-Allow-Headers'] = headers | |
return response | |
app.after_request(add_cors_headers) |
(?:https?://)?(?:[a-zA-Z0-9\-]+\.)?(?:amazon|amzn){1}\.(?P<tld>[a-zA-Z\.]{2,})\/(gp/(?:product|offer-listing|customer-media/product-gallery)/|exec/obidos/tg/detail/-/|o/ASIN/|dp/|(?:[A-Za-z0-9\-]+)/dp/)?(?P<ASIN>[0-9A-Za-z]{10}) | |
I created this a number of years ago for an irc bot (https://github.com/rmmh/skybot) to recognize amazon urls. Keep forgetting to hang onto it. |
Attention: the list was moved to
https://github.com/dypsilon/frontend-dev-bookmarks
This page is not maintained anymore, please update your bookmarks.
from datetime import datetime | |
class LRUCacheItem(object): | |
"""Data structure of items stored in cache""" | |
def __init__(self, key, item): | |
self.key = key | |
self.item = item | |
self.timestamp = datetime.now() |
# A trivial code for solving the Colossal Cue Adventure | |
# URL: http://adventure.cueup.com/ | |
# Level 1: The VAX's MTH$RANDOM % 36 Roulette | |
def vax_rng_next(x): | |
"""Generate the next pseudo-random number.""" | |
a, c, m = 69069, 1, 2**32 | |
return (a * x + c) % m |
c = LinkedIn::Client.new | |
c.authorize_from_access authentication.token, authentication.secret | |
c.search(fields: [{:people => [:picture_url]}]).people.all.first.try(:picture_url) | |
#or better | |
c.profile(:fields => ['picture-urls::(original)']).picture_urls.all.first |