Skip to content

Instantly share code, notes, and snippets.

@braebo
braebo / localStorageStore.js
Last active March 23, 2023 21:41
Async LocalStorage Svelte Store
import { writable } from 'svelte/store';
const client = typeof window !== "undefined";
const asyncLocalStorage = {
setItem: function (key, value) {
return Promise.resolve().then(function () {
typeof value != 'string'
? localStorage.setItem(key, JSON.stringify(value))
: localStorage.setItem(key, value);
@getify
getify / 1.html
Last active May 10, 2023 03:25
Ever noticed how vw/vh units in CSS seem to be a bit unreliable on various devices (especially mobile)? Here's my solution.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
<title>Test Page</title>
<script>
// early compute the vw/vh units more reliably than CSS does itself
computeViewportDimensions();
@kawanet
kawanet / material-colors.json
Last active June 27, 2024 14:57
Material Design Style Color Palette as JSON
{
"red": {
"50": "#ffebee",
"100": "#ffcdd2",
"200": "#ef9a9a",
"300": "#e57373",
"400": "#ef5350",
"500": "#f44336",
"600": "#e53935",
"700": "#d32f2f",
@GuilhermeHideki
GuilhermeHideki / coalesce.py
Created April 27, 2016 07:31
Python coalesce
def coalesce(*args):
"""Returns the first not None item. Similar to ?? in C#.
It's different from a or b, where false values are invalid.
:param args: list of items for checking
:return the first not None item, or None
"""
return next((arg for arg in args if arg is not None))
@66Ton99
66Ton99 / logging_to_str.py
Created August 28, 2015 16:26
Capturing Python Log Output In A Variable
import logging
from StringIO import StringIO as StringBuffer
logger = logging.getLogger('basic_logger')
logger.setLevel(logging.DEBUG)
### Setup the console handler with a StringIO object
log_capture_string = StringBuffer()
# log_capture_string.encoding = 'cp1251'
ch = logging.StreamHandler(log_capture_string)