Skip to content

Instantly share code, notes, and snippets.

View zjffun's full-sized avatar
:octocat:
I may be slow to respond.

Jufeng Zhang zjffun

:octocat:
I may be slow to respond.
  • ByteDance
  • Beijing, China
  • 14:49 (UTC +08:00)
View GitHub Profile
@gregersrygg
gregersrygg / fixTouch.js
Created October 3, 2012 17:52
Fix touch event bug in iOS 4 and Android 4.0 when page is scrolled
/* Fix touch event bug in iOS 4 and Android 4.0 when page is scrolled.
* This function will take a touch object (evt.touches[x]) and return
* an object litteral with corrected values for clientX and clientY.
*/
function fixTouch (touch) {
var winPageX = window.pageXOffset,
winPageY = window.pageYOffset,
x = touch.clientX,
y = touch.clientY;
@caseywatts
caseywatts / bookmarkleting.md
Last active November 1, 2024 15:13
Making Bookmarklets

This is one chapter of my "Chrome Extension Workshops" tutorial, see the rest here: https://gist.github.com/caseywatts/8eec8ff974dee9f3b247

Unrelated update: my book is out! Debugging Your Brain is an applied psychology / self-help book

Making Bookmarklets

I'm feeling very clever. I've got this sweet line of javascript that replaces "cloud" with "butt". My mom would LOVE this, but she doesn't computer very well. I'm afraid to show her the Developer Console and have her type/paste this in. But she IS pretty good at bookmarks, she knows just how to click those!

A bookmark normally takes you to a new web page. A bookmarklet is a bookmark that runs javascript on the current page instead of taking you to a new page. To declare that it is a bookmarklet, the "location" it points to starts with javascript:.

@domenic
domenic / 0-github-actions.md
Last active May 26, 2024 07:43
Auto-deploying built products to gh-pages with Travis

Auto-deploying built products to gh-pages with GitHub Actions

This is a set up for projects which want to check in only their source files, but have their gh-pages branch automatically updated with some compiled output every time they push.

A file below this one contains the steps for doing this with Travis CI. However, these days I recommend GitHub Actions, for the following reasons:

  • It is much easier and requires less steps, because you are already authenticated with GitHub, so you don't need to share secret keys across services like you do when coordinate Travis CI and GitHub.
  • It is free, with no quotas.
  • Anecdotally, builds are much faster with GitHub Actions than with Travis CI, especially in terms of time spent waiting for a builder.
@kevinSuttle
kevinSuttle / webpack.banner.js
Created October 12, 2016 16:50
Webpack auto-injecting banner into each file
const pkg = require('./package.json');
const moment = require('moment');
const localTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone
const timeStamp = moment().format('LLLL');
const banner = `
Generated on ${timeStamp} - ${localTimeZone}
Description: ${pkg.description}
Package: ${pkg.name}
Version: v${pkg.version}
Contributors: ${pkg.contributors.map(function(contributor){ return contributor})}
@sindresorhus
sindresorhus / esm-package.md
Last active November 8, 2024 03:55
Pure ESM package

Pure ESM package

The package that linked you here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.