Skip to content

Instantly share code, notes, and snippets.

View sundayu's full-sized avatar

Dayu Sun sundayu

  • Cisco
  • Hangzhou/CN
  • 23:06 (UTC +08:00)
View GitHub Profile
@sundayu
sundayu / support.js
Created July 28, 2023 02:31
Push notifications
// Check if the browser supports push notifications.
if ("serviceWorker" in navigator && "PushManager" in window) {
try {
// Register the service worker.
const swReg = await navigator.serviceWorker.register("/sw.js");
// Subscribe for push notifications.
const pushSubscription = await swReg.pushManager.subscribe({
userVisibleOnly: true
});
@sundayu
sundayu / app.validator.coffee
Last active December 16, 2015 07:49
JavaScript: validator
App.validator =
check: (str, regexp)->
@[regexp].test str
url: /^(https?:)\/\/([a-z0-9]([-a-z0-9]*[a-z0-9])?\.)+([a-zA-z]{2,6})(\/[a-zA-Z0-9$_.+!#*(),;\/?:@&~=%-]*)?$/
email: /^([\w\.\-\+\=]+)@((?:[a-z0-9\-_]+\.)+[a-z]{2,6})$/i
@sundayu
sundayu / protobuf.js
Created July 28, 2011 07:26
Reads an unsigned 64 bit integer from the buffer at the specified offset; readUInt64, writeUInt64 for Nodejs
var _0x100000000000000 = 0x100000000000000,
_0x1000000000000 = 0x1000000000000,
_0x10000000000 = 0x10000000000,
_0x100000000 = 0x100000000,
_0x1000000 = 0x1000000,
_0x10000 = 0x10000,
_0x100 = 0x100,
_0xff = 0xff,
_0x80 = 0x80;
package {
import flash.events.EventDispatcher;
import flash.net.FileReference;
import flash.events.*;
import flash.external.ExternalInterface;
import ExternalCall;
internal class FileItem