Skip to content

Instantly share code, notes, and snippets.

@alisey
alisey / scrollSelectionIntoView.js
Created September 18, 2012 17:45
Scroll selection into view
// Scroll to selection focus, but only if it's out of view. Align selection
// focus with the top or bottom edge of its scroll-container. Return true
// on success.
// * there might be several nested scroll-containers, including window
// * must not try to scroll overflow:hidden and overflow:visible elements
// * no scrolling should happen if selection focus is visible
// * selection is not necessarily collapsed
// * range.getBoundingClientRect doesn't work for collapsed ranges
// * Opera reports incorrect startOffset and endOffset for collapsed ranges
// outside of text nodes (e.g. between 2 <br> elements), range.insertNode
@srz-zumix
srz-zumix / WindowsUpdate.ps1
Created September 14, 2016 04:12
WindowsUpdate powershell
Write-Host "--- Running Windows Update ---"
Write-Host "Searching for updates..."
$updateSession = new-object -com "Microsoft.Update.Session"
$updateSearcher = $updateSession.CreateupdateSearcher()
$searchResult = $updateSearcher.Search("IsInstalled=0 and Type='Software' and AutoSelectOnWebSites=1")
Write-Host "List of applicable items on the machine:"
if ($searchResult.Updates.Count -eq 0) {
Write-Host "There are no applicable updates."
}
else
@ca0v
ca0v / debounce.ts
Last active June 19, 2024 11:20
Typescript Debounce
// ts 3.6x
function debounce<T extends Function>(cb: T, wait = 20) {
let h = 0;
let callable = (...args: any) => {
clearTimeout(h);
h = setTimeout(() => cb(...args), wait);
};
return <T>(<any>callable);
}
@Eotones
Eotones / README.md
Last active March 14, 2024 08:30
speechSynthesis強制使用Chrome中的Google小姐中文語音

speechSynthesis強制使用Chrome中的Google小姐中文語音

網路上的window.speechSynthesis教學主要都只有說切換指定語言

像是這樣就能切換成中文語音:

const synth = window.speechSynthesis;

const speak = (msg) => {
// ==UserScript==
// @name 新しいスクリプト 421815
// @version 1
// @match https://wiki.greasespot.net/GM.xmlHttpRequest
// @match http://example.com/
// @grant GM.xmlHttpRequest
// ==/UserScript==
function get(url) {
return new Promise(resolve => {
@princefishthrower
princefishthrower / export-source-from-docker-tag.sh
Last active July 25, 2024 04:29
Export the source code from any Docker tag!
#!/bin/bash
#
# Extracts the source code of any Docker tag!
# Inspired by Sambhav Jain's post on DEV: https://dev.to/sambhav2612/reverse-engineering-a-docker-image-i8c
# Simply pass:
# 1. The desired Docker image tag you want to get the source code for
# 2. The target folder to put the source code in
#
# Example usage:
# ./export-source-from-docker-tag.sh gcr.io/google-samples/gb-frontend:v4 docker-source