Skip to content

Instantly share code, notes, and snippets.

View weilinzung's full-sized avatar

Wei weilinzung

  • Canada
View GitHub Profile
@mccrodp
mccrodp / domlistener.js
Created June 2, 2017 06:49
DOM Mutation Listener - Google Maps
var observeDOM = (function(){
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver,
eventListenerSupported = window.addEventListener;
return function(obj, callback){
if( MutationObserver ){
// define a new observer
var obs = new MutationObserver(function(mutations, observer){
if( mutations[0].addedNodes.length || mutations[0].removedNodes.length )
callback();
@javilobo8
javilobo8 / download-file.js
Last active March 17, 2025 14:25
Download files with AJAX (axios)
axios({
url: 'http://localhost:5000/static/example.pdf',
method: 'GET',
responseType: 'blob', // important
}).then((response) => {
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'file.pdf');
document.body.appendChild(link);
@schmich
schmich / npm-prerelease.md
Last active June 26, 2024 13:20
Publish a prerelease package to NPM
  • Update package.json, set version to a prerelease version, e.g. 2.0.0-rc1, 3.1.5-rc4, ...
  • Run npm pack to create package
  • Run npm publish <package>.tgz --tag next to publish the package under the next tag
  • Run npm install --save package@next to install prerelease package
@pts-moog16
pts-moog16 / gulp.dev.js
Last active May 6, 2021 20:48
Gulp task for starting webpack-dev-server
const webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const webpackConfig = require('./webpack.config.js');
const browserSync = require('browser-sync');
// a nice npm module written to have BrowserSync work with Webpack
// and webpack-dev-server
const BrowserSyncPlugin = require('browser-sync-webpack-plugin');
const renderTemplate = require('./build/gulp/template');
const clients = require('./build/gulp/clients')();
let browserSyncInstance;
@nfarina
nfarina / mock-storage.js
Last active November 23, 2023 15:50
Mock Google Cloud Storage for JS
//
// Quick & Dirty Google Cloud Storage emulator for tests. Requires
// `stream-buffers` from npm. Use it like this:
//
// `new MockStorage().bucket('my-bucket').file('my_file').createWriteStream()`
//
class MockStorage {
buckets: {[name: string]: MockBucket};
@martinherweg
martinherweg / browserSync.js
Last active May 29, 2021 08:07
Webpack + BrowserSync + HMR
/**
|--------------------------------------------------------------------------
| gulp browser-sync
|--------------------------------------------------------------------------
*
* Browser Sync
* @description Refresh the Brwoser after File Change.
* Combined with webpack for HMR or Content Reload
*
* @package generator-mh-boilerplate
@hirejordansmith
hirejordansmith / magnific-popup-gallery-image-plus-video.js
Last active February 5, 2025 08:47
How to show images and video in Magnific Popup Gallery
@Toxicable
Toxicable / file-upload.component.ts
Created October 23, 2016 07:18
How to upload files in angular 2
/**
* Created by Fabian on 19/10/2016.
*/
import { Component, ElementRef, Input } from '@angular/core';
import { Http } from '@angular/http';
@Component({
selector: 'file-upload',
template: '<input type="file" [attr.multiple]="multiple ? true : null" (change)="upload()" >'
})
export class FileUploadComponent {
@smhmic
smhmic / onDomInsert.js
Created August 3, 2016 20:39
Listener for dynamically inserted DOM elements
/**
* @function onDomInsert - Listener for nodes inserted into DOM.
* Does NOT monitor when things are removed.
* Based on http://stackoverflow.com/a/14570614/445295
* @param [DOMNode] el - Optional. The element to listen on. Defaults to document.
* @param [Function] cb - Callback. Called with inserted element as only arg.
*/
var onDomInsert = (function(){
'use strict';
@johannesjo
johannesjo / table-to-json.js
Last active October 9, 2024 06:06
Snippet to convert html table to json (to be used with google chrome or similiar)
function tableToJson(table) {
var data = [];
// first row needs to be headers
var headers = [];
for (var i=0; i<table.rows[0].cells.length; i++) {
headers[i] = table.rows[0].cells[i].innerHTML.toLowerCase().replace(/ /gi,'');
}
// go through cells