Skip to content

Instantly share code, notes, and snippets.

Avatar
💡
Available

Wei He wei

💡
Available
View GitHub Profile
View keybase.md

Keybase proof

I hereby claim:

  • I am wei on github.
  • I am towei (https://keybase.io/towei) on keybase.
  • I have a public key whose fingerprint is 01F3 7324 4CA2 866D 1E17 B054 D380 E53F 849A 5C7C

To claim this, I am signing this object:

@wei
wei / auto-select-first.js
Last active June 16, 2022 07:36
Google Maps API AutoComplete Auto Select First on Enter
View auto-select-first.js
selectFirstOnEnter(input){
const _addEventListener = input.addEventListener;
let hasHitDown = false;
// Simulate a 'down arrow' keypress on hitting 'return' when no pac suggestion is selected, and then trigger the original listener.
function addEventListenerWrapper(type, listener) {
if (type === "keydown") {
var orig_listener = listener;
listener = function (event) {
if (event.which === 13) {
if (!hasHitDown) {
@wei
wei / Google-Analytics-outbound-links.js
Last active January 23, 2020 21:10
Setup Google Analytics to track outbound links. Supports target="_blank".
View Google-Analytics-outbound-links.js
@wei
wei / NginxWWWRedirection.md
Last active July 30, 2017 02:07
Nginx WWW Redirection
View NginxWWWRedirection.md

Nginx WWW Redirection

Redirect non-www to www

For Single Domain:

server {
    server_name example.com;
    return 301 $scheme://www.example.com$request_uri;
}
@wei
wei / whois-watch.sh
Last active August 4, 2017 13:26 — forked from zhovner/whois-change.sh
Monitor whois changes
View whois-watch.sh
#!/bin/bash
#
# Run this script once per minute
#
# * * * * * /path/to/whois-watch.sh google.com apple.com >> /var/log/whois-watch.log 2>&1
# update username in mail command
# update sed command depending on server return text
#
@wei
wei / generate-identicon.js
Created June 20, 2016 22:02
Generate Icons with SVG and Color Rounded Background
View generate-identicon.js
var COLORS = [
{iconColor: '#536D2F', bgColor: '#DDE2D5'},
{iconColor: '#5093A1', bgColor: '#DBE9EC'},
{iconColor: '#AF2F30', bgColor: '#EFD6D6'},
{iconColor: '#BE8341', bgColor: '#F2E6D9'},
{iconColor: '#784FA0', bgColor: '#E4DCEC'},
{iconColor: '#FFFFFF', bgColor: '#58B6E1'}
]
var fs = require('fs');
@wei
wei / fullbackup.php
Created June 2, 2015 22:15
CPanel Full Backup Cron Script
View fullbackup.php
<?php
// PHP script to allow periodic cPanel backups automatically, optionally to a remote FTP server.
// Cron Job Command: /usr/local/bin/php /home/<cpanel-username>/fullbackup.php
// This script contains passwords. It is important to keep access to this file secure (we would ask you to place it in your home directory, not public_html)
// You need create 'backups' folder in your home directory ( or any other folder that you would like to store your backups in ).
// ********* THE FOLLOWING ITEMS NEED TO BE CONFIGURED *********
@wei
wei / Manually Pre-Sign Amazon Put Request
Created May 16, 2015 06:25
Manually Pre-Sign Amazon Put Request
View Manually Pre-Sign Amazon Put Request
var hmacSha1Base64 = function (message) {
return require("crypto").createHmac('sha1', process.env.AMAZON_SECRET_ACCESS_KEY)
.update(message)
.digest('base64')
}
var expires = Math.floor(Date.now() / 1000) + 60 * 60 * 24 * 365
var put_request = "PUT\n" + md5Base64 + "\n"+contentType+"\n"+expires+"\n/"+ "xxxxxxx/" + bucketObjectKey