Skip to content

Instantly share code, notes, and snippets.

View fallenleavesguy's full-sized avatar
🌴
On vacation

fallenleavesbuy fallenleavesguy

🌴
On vacation
View GitHub Profile
@fallenleavesguy
fallenleavesguy / observe-undefined-dom-text.js
Created November 2, 2023 06:45
observe undefined dom text
(function () {
function observeUndefinedValue(selector, cb) {
const targetNode = document.querySelector(selector);
if (!targetNode) {
return;
}
cb(targetNode);
const config = { attributes: false, childList: true, subtree: false };
@fallenleavesguy
fallenleavesguy / union.sql
Created July 1, 2023 03:12
union multiple different table in sql
select username, steamid from pavlov_pc_users UNION ALL select username, 0 as steamid from pavlov_oculus_users
@fallenleavesguy
fallenleavesguy / what-forces-layout.md
Created April 6, 2023 01:26 — forked from paulirish/what-forces-layout.md
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
@fallenleavesguy
fallenleavesguy / onWindowFocus.ts
Created March 8, 2023 08:39 — forked from tannerlinsley/onWindowFocus.ts
A utility function to detect window focusing without false positives from iframe focus events
type State = {
added: boolean;
interval: false | ReturnType<typeof setInterval>;
inFrame: boolean;
callbacks: Array<SetFocusedCallback>;
};
type EnrichedHTMLIFrameElement = HTMLIFrameElement & { ___onWindowFocusHandled: boolean };
type SetFocusedCallback = (focused?: boolean) => void;

Problem

I have two Github accounts: oanhnn (personal) and superman (for work). I want to use both accounts on same computer (without typing password everytime, when doing git push or pull).

Solution

Use ssh keys and define host aliases in ssh config file (each alias for an account).

How to?

  1. Generate ssh key pairs for accounts and add them to GitHub accounts.
@fallenleavesguy
fallenleavesguy / scroll-offset.js
Created January 13, 2020 14:18 — forked from nathansmith/scroll-offset.js
Check if the user is scrolled to the bottom of the page.
window.onscroll = function() {
var d = document.documentElement;
var offset = d.scrollTop + window.innerHeight;
var height = d.offsetHeight;
console.log('offset = ' + offset);
console.log('height = ' + height);
if (offset === height) {
console.log('At the bottom');
@fallenleavesguy
fallenleavesguy / format.date.js
Created December 29, 2019 12:25 — forked from ptquang86/format.date.js
JavaScript Date Format
//http://blog.stevenlevithan.com/archives/date-time-format
//http://stevenlevithan.com/assets/misc/date.format.js
/*
* Date Format 1.2.3
* (c) 2007-2009 Steven Levithan <stevenlevithan.com>
* MIT license
*
* Includes enhancements by Scott Trenda <scott.trenda.net>
* and Kris Kowal <cixar.com/~kris.kowal/>
@fallenleavesguy
fallenleavesguy / tcping.py
Created February 18, 2019 04:49 — forked from defnull/tcping.py
TCPing
def ping(server, port):
''' Check if a server accepts connections on a specific TCP port '''
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((server, port))
s.close()
return True
except socket.error:
return False
@fallenleavesguy
fallenleavesguy / ellipse-interpolation.js
Last active January 23, 2018 01:04
ellipse interpolation
export function ellipseInterpolation(x, y, radiusX, radiusY, startProgress = 0, clockwise = true) {
const dir = ( clockwise ? 1 : -1);
return function (t) {
t = (t + startProgress);
const radian = t * Math.PI * dir * 2;
return {
x: radiusX * Math.cos(radian) + x,
y: radiusY * Math.sin(radian) + y
};
}
@fallenleavesguy
fallenleavesguy / search-jpg.m
Last active October 7, 2017 18:13
recursive search jpg file in home.m
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
NSLog(@"beginning search...");
@autoreleasepool
{
NSFileManager *manager = [NSFileManager defaultManager];
NSString *home = [@"~" stringByExpandingTildeInPath];