Skip to content

Instantly share code, notes, and snippets.

View mrhung's full-sized avatar
🎯
Focusing

MrHung Nguyễn mrhung

🎯
Focusing
View GitHub Profile
@mrhung
mrhung / puppeteer-click-by-text.js
Created June 15, 2022 17:31 — forked from tokland/puppeteer-click-by-text.js
Click link by text in Puppeteer
const puppeteer = require('puppeteer');
const escapeXpathString = str => {
const splitedQuotes = str.replace(/'/g, `', "'", '`);
return `concat('${splitedQuotes}', '')`;
};
const clickByText = async (page, text) => {
const escapedText = escapeXpathString(text);
const linkHandlers = await page.$x(`//a[contains(text(), ${escapedText})]`);
@mrhung
mrhung / gist:eb538f533b3027897b21281794990fb6
Created April 12, 2021 19:56 — forked from pitch-gist/gist:2999707
HTML: Simple Maintenance Page
<!doctype html>
<title>Site Maintenance</title>
<style>
body { text-align: center; padding: 150px; }
h1 { font-size: 50px; }
body { font: 20px Helvetica, sans-serif; color: #333; }
article { display: block; text-align: left; width: 650px; margin: 0 auto; }
a { color: #dc8100; text-decoration: none; }
a:hover { color: #333; text-decoration: none; }
</style>
@mrhung
mrhung / readability.js
Created April 6, 2021 03:06 — forked from jakedahn/readability.js
Readability.js
/*jslint undef: true, nomen: true, eqeqeq: true, plusplus: true, newcap: true, immed: true, browser: true, devel: true, passfail: false */
/*global window: false, readConvertLinksToFootnotes: false, readStyle: false, readSize: false, readMargin: false, Typekit: false, ActiveXObject: false */
var dbg = (typeof console !== 'undefined') ? function(s) {
console.log("Readability: " + s);
} : function() {};
/*
* Readability. An Arc90 Lab Experiment.
* Website: http://lab.arc90.com/experiments/readability
@mrhung
mrhung / s3cmd_sync.sh
Created March 31, 2021 07:44 — forked from niraj-shah/s3cmd_sync.sh
s3cmd commands to sync folders to AWS S3
# Command Line to run from terminal
# Logs result to file s3_backup.log
# Command will run in the background
s3cmd sync -v /path/to/folder/ s3://s3-bucket/folder/ > s3_backup.log 2>&1 &
# Crontab command to sync folder to S3
# Command will run 1am every day and logs result to /root/s3_backup.log
0 1 * * * /usr/bin/s3cmd sync -rv /path/to/folder/ s3://s3-bucket/folder/ >> /root/s3_backup.log
@mrhung
mrhung / directUploadToS3.js
Created March 24, 2021 18:00 — forked from DWboutin/directUploadToS3.js
Direct image url to S3 wiht axios and nodejs
import AWS from 'aws-sdk';
import stream from 'stream'
import axios from 'axios';
export default async (url, filename, callback) => {
const s3 = new AWS.S3({ params: { Bucket: process.env.STATIC_MAPS_BUCKET }});
let contentType = 'application/octet-stream'
let promise = null
const uploadStream = () => {
var app = express();
app.io = require('socket.io')();
var routes = require('./routes/index')(app.io);
app.use('/', routes);
@mrhung
mrhung / search_partial_string_array.php
Created January 8, 2021 09:19 — forked from zuhairkareem/search_partial_string_array.php
Search partial string in an array in PHP
<?php
/**
* First Method.
*/
function array_search_partial($arr, $keyword) {
foreach($arr as $index => $string) {
if (strpos($string, $keyword) !== FALSE)
return $index;
}
}
@mrhung
mrhung / square_thumbnail.php
Created August 2, 2019 17:01 — forked from ZachMoreno/square_thumbnail.php
Create Square Thumbnails
<?php
function create_square_thumbnails($userfile_name, $userfile_type)
{
//get the file and figure out what type of file it is and some of its attributes
switch ($userfile_type)
{
case "image/pjpeg": $tempbig = imagecreatefromjpeg(IMG_PATH.$userfile_name); break;
case "image/jpeg": $tempbig = imagecreatefromjpeg(IMG_PATH.$userfile_name); break;
case "image/jpg": $tempbig = imagecreatefromjpeg(IMG_PATH.$userfile_name); break;
case "image/gif": $tempbig = imagecreatefromgif(IMG_PATH.$userfile_name); break;

Download courses from learning sites with youtube-dl

You can download whole courses from an array of tutorial sites with the CLI tool youtube-dl. In the example further down I'm using my Pluralsight account to get videos from a course at their site. Here is a list of all supported sites that you can download from with this tool

The flags you have to supply may vary depending on which site you make a request to.

You can get a free 3 month trial to Pluralsight by signing up for free to Visual Studio Dev Essentials

Installation

@mrhung
mrhung / youtube-dl.md
Created April 23, 2019 17:13
Using youtube-dl to download courses from Pluralsight

Download courses from learning sites with youtube-dl

You can download whole courses from an array of tutorial sites with the CLI tool youtube-dl. In the example further down I'm using my Pluralsight account to get videos from a course at their site. Here is a list of all supported sites that you can download from with this tool

The flags you have to supply may vary depending on which site you make a request to.

You can get a free 3 month trial to Pluralsight by signing up for free to Visual Studio Dev Essentials

Installation