Skip to content

Instantly share code, notes, and snippets.

View kenng's full-sized avatar
💭
calm

Ken Ng kenng

💭
calm
View GitHub Profile
@kenng
kenng / README.md
Created August 4, 2019 07:47 — forked from joyrexus/README.md
Vanilla JS equivalents of jQuery methods

Sans jQuery

Events

// jQuery
$(document).ready(function() {
  // code
})
@kenng
kenng / lambda-email.py
Created May 13, 2019 04:10 — forked from rambabusaravanan/lambda-email.py
AWS Lambda Function to send SMTP Email
import smtplib
import os
def send_email(host, port, username, password, subject, body, mail_to, mail_from = None, reply_to = None):
if mail_from is None: mail_from = username
if reply_to is None: reply_to = mail_to
message = """From: %s\nTo: %s\nReply-To: %s\nSubject: %s\n\n%s""" % (mail_from, mail_to, reply_to, subject, body)
print (message)
try:
@kenng
kenng / listAllEventListeners.js
Created April 7, 2019 14:56 — forked from dmnsgn/listAllEventListeners.js
List all event listeners in a document
const listeners = (function listAllEventListeners() {
let elements = [];
const allElements = document.querySelectorAll('*');
const types = [];
for (let ev in window) {
if (/^on/.test(ev)) types[types.length] = ev;
}
for (let i = 0; i < allElements.length; i++) {
const currentElement = allElements[i];
@kenng
kenng / php
Created February 13, 2019 07:12
phpmailer
<?php
/**
* PHPMailer - PHP email creation and transport class.
* PHP Version 5.5.
*
* @see https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
*
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
* @author Jim Jagielski (jimjag) <jimjag@gmail.com>
* @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
@kenng
kenng / php
Last active February 27, 2019 06:12
php mail function
<?php
class IwMail {
protected $subject;
protected $headers;
protected $content;
protected $to;
protected $from;
public $mail;
@kenng
kenng / php
Last active January 30, 2019 16:02
php debug
public static function WriteErrorFile(String $msg) {
$fpath = base_path() . '/errors.log';
$fpath = "/Applications/AMPPS/www/lwnew.thelivingwellco.com.sg/wp-content/plugins/itwonders-woocommerce-deposit/errors.log";
error_log(print_r($msg, TRUE), 3, $fpath);
}
public static function backtrace($skip=0, $limit=12) {
$dump = [];
$mydump = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, $limit);
@kenng
kenng / javascript
Created January 22, 2019 07:33
particle json
{
"particles": {
"number": {
"value": 80,
"density": {
"enable": true,
"value_area": 800
}
},
"color": {
@kenng
kenng / important.css
Created January 22, 2019 01:59 — forked from tzi/important.css
How to set an !important css property in javascript
.test {
height: 139px;
width: 96px
}
@kenng
kenng / javascript
Created December 16, 2018 15:53
svg download
function loadScript(url) {
var script = document.createElement("script"); // create a script DOM node
script.src = url; // set its src to the provided URL
document.head.appendChild(script);
}
loadScript('https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.3/FileSaver.min.js')
/*
pass in either myDOM, myid, or myclass, just one of them