Skip to content

Instantly share code, notes, and snippets.

View isocroft's full-sized avatar
💯
Documenting Software...

Ifeora Okechukwu isocroft

💯
Documenting Software...
View GitHub Profile
@eligrey
eligrey / object-watch.js
Created April 30, 2010 01:38
object.watch polyfill in ES5
/*
* object.watch polyfill
*
* 2012-04-03
*
* By Eli Grey, http://eligrey.com
* Public Domain.
* NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
*/
@sstephenson
sstephenson / back_forward.js
Created December 13, 2010 21:55
How to detect whether a hash change came from the Back or Forward button
var detectBackOrForward = function(onBack, onForward) {
hashHistory = [window.location.hash];
historyLength = window.history.length;
return function() {
var hash = window.location.hash, length = window.history.length;
if (hashHistory.length && historyLength == length) {
if (hashHistory[hashHistory.length - 2] == hash) {
hashHistory = hashHistory.slice(0, -1);
onBack();
@blafrance
blafrance / ga-twitter.js
Created November 11, 2012 04:50 — forked from kressaty/ga-twitter.js
Twitter Button Google Analytics
// This assumes that you have included the Tweet button via the standard Twitter JS include
// Thanks to Google for most of this code, see the Social Interaction Analytics guide at
// https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingSocial
// To track a Tweet, subscribe to the tweet event (note the additional function required
// to determine the query parameter being sent to Twitter):
function trackTwitter(intent_event) {
if (intent_event) {
var opt_pagePath;
if (intent_event.target && intent_event.target.nodeName == 'IFRAME') {
@Thecarisma
Thecarisma / device-enabler.bat
Created December 28, 2019 22:05
Use brute-force method to enable a device when disabled by device control programs (e.g anti-virus). This simple script can be used to activate a disk drive even if a device control program is up.
@echo off
REM download the microsoft devcon app https://docs.microsoft.com/en-us/windows-hardware/drivers/devtest/devcon
REM Download x64 if your arch is x64 same for x32
REM change this 'USBSTOR\DISK&VEN_WD&PROD_ELEMENTS_25A2&REV_1021\57584131413438324C384543&0' to your device instace path
REM Run as Administrator
:exec
devcon enable @"USBSTOR\DISK&VEN_WD&PROD_ELEMENTS_25A2&REV_1021\57584131413438324C384543&0"
goto:exec
@Widdershin
Widdershin / ssr.md
Last active May 1, 2024 17:36
The absurd complexity of server-side rendering

In the olden days, HTML was prepared by the server, and JavaScript was little more than a garnish, considered by some to have a soapy taste.

After a fashion, it was decided that sometimes our HTML is best rendered by JavaScript, running in a user's browser. While some would decry this new-found intimacy, the age of interactivity had begun.

But all was not right in the world. Somewhere along the way, we had slipped. Our pages went uncrawled by Bing, time to first meaningful paint grew faster than npm, and it became clear: something must be done.

And so it was decided that the applications first forged for the browser would also run on the server. We would render our HTML using the same logic on the server and the browser, and reap the advantages of both worlds. In a confusing series of events a name for this approach was agreed upon: Server-side rendering. What could go wrong?

In dark rooms, in hushed tones, we speak of colours.

@mykeels
mykeels / snake-camel.d.ts
Created May 30, 2023 23:25
Typings for the snake-camel npm package https://www.npmjs.com/package/snake-camel
type CamelToSnakeCase<S extends string> = S extends `${infer T}${infer U}`
? `${T extends Capitalize<T> ? '_' : ''}${Lowercase<T>}${CamelToSnakeCase<U>}`
: S
type SnakeToCamelCase<S extends string> = S extends `${infer T}_${infer U}`
? `${T}${Capitalize<SnakeToCamelCase<U>>}`
: S
type StringKeys<TEntity extends {}> = {
[key in keyof TEntity]: key extends string ? key : never
}[keyof TEntity]
type IsLiteral<TValue> = TValue extends string | number | boolean | symbol

This gist is a simple no-brainer description of the 3 ways (actually 2.5) the Web handle events.

<tag onclick />

The declarative inline HTML event listener is mostly an indirection of DOM Level 0 events, meaning this simply uses the equivalent of tag.onclick = listener behind the scene.

Example

click me