Skip to content

Instantly share code, notes, and snippets.

View nguyenbathanh's full-sized avatar

Thanh Nguyen nguyenbathanh

View GitHub Profile
function getHightlightCoords() {
var pageIndex = PDFViewerApplication.pdfViewer.currentPageNumber - 1;
var page = PDFViewerApplication.pdfViewer.getPageView(pageIndex);
var pageRect = page.canvas.getClientRects()[0];
var selectionRects = window.getSelection().getRangeAt(0).getClientRects();
var viewport = page.viewport;
var selected = selectionRects.map(function (r) {
return viewport.convertToPdfPoint(r.left - pageRect.x, r.top - pageRect.y).concat(
viewport.convertToPdfPoint(r.right - pageRect.x, r.bottom - pageRect.y));
});
@nguyenbathanh
nguyenbathanh / PDFViewController.swift
Created May 24, 2023 10:23 — forked from derickito/PDFViewController.swift
iOS PDFKit: How to add a highlight annotation
override func viewDidLoad() {
createMenu()
}
private func createMenu() {
let highlightItem = UIMenuItem(title: "Highlight", action: #selector(highlight(_:)))
UIMenuController.shared.menuItems = [highlightItem]
}
@objc private func highlight(_ sender: UIMenuController?) {
@nguyenbathanh
nguyenbathanh / install-redis.md
Created September 22, 2020 14:42 — forked from hackedunit/install-redis.md
Install and configure Redis on Ubuntu 16.04 with systemd
  1. Install pre-requisities

sudo apt-get install build-essential tcl

  1. Install Redis
cd /tmp
curl -O http://download.redis.io/redis-stable.tar.gz
tar xzvf redis-stable.tar.gz
@nguyenbathanh
nguyenbathanh / http2_apache2_ubuntu16.04.md
Created August 7, 2020 09:31 — forked from GAS85/http2_apache2_ubuntu16.04.md
How to Enable HTTP/2 in Apache 2.4 on Ubuntu 16.04

Requirements

  • A self-managed VPS or dedicated server with Ubuntu 16.04 running Apache 2.4.xx.
  • For Ubuntu 18.04 please read here --> https://gist.github.com/GAS85/8dadbcb3c9a7ecbcb6705530c1252831
  • A registered domain name with working HTTPS (TLS/SSL). HTTP/2 only works alongside HTTPS because most browsers, including Firefox and Chrome, don’t support HTTP/2 in cleartext (non-TLS) mode.
@nguyenbathanh
nguyenbathanh / find-old-branches.sh
Created March 5, 2020 00:58 — forked from mroderick/find-old-branches.sh
A small script to find stale branches
#!/bin/bash
# This is a very naive script, it doesn't do grouping and returns all branches
# I only really care about branches that have not seen commits in two months
#
# I am hoping to find some time to write a tool that can output these reports for me
# In the meantime, I am using this
echo "Merged branches"
for branch in `git branch -r --merged | grep -v HEAD`;do echo -e `git log --no-merges -n 1 --format="%ci, %cr, %an, %ae, " $branch | head -n 1` \\t$branch; done | sort -r
@nguyenbathanh
nguyenbathanh / run.py
Last active September 15, 2019 02:49
Django Development Server - Skip system checks and migration checks
# You need to put this under <app>/management/commands/run.py
# where <app> is whatever appropriate app should have this command.
# Then you can invoke it with ./manage.py run and you'll get something like:
# Performing system checks...
# SKIPPING SYSTEM CHECKS!
# SKIPPING MIGRATION CHECKS!
This file has been truncated, but you can view the full file.
[
{
"name": "Apple",
"value": "214480",
"year": 2018,
"lastValue": "211447.400000003",
"rank": 1
},
{
"name": "Apple",
@nguyenbathanh
nguyenbathanh / encoder.py
Last active March 20, 2020 13:59
MongoEngineJSONEncoder. Dump the data in a BaseDocument ,QuerySet of Mongo documents to JSON
import datetime
import json
from bson import ObjectId
from mongoengine.base import BaseDocument
from mongoengine.queryset import QuerySet
class MongoengineEncoder(json.JSONEncoder):
def default(self, obj):
@nguyenbathanh
nguyenbathanh / squash-commits.sh
Created August 17, 2018 03:28 — forked from jbub/squash-commits.sh
git squash last two commits into one
git rebase --interactive HEAD~2
# we are going to squash c into b
pick b76d157 b
pick a931ac7 c
# squash c into b
pick b76d157 b
s a931ac7 c
@nguyenbathanh
nguyenbathanh / encoder.py
Created April 15, 2018 06:21 — forked from gati/encoder.py
Mongoengine JSON encoder
import json
from collections import Iterable
from bson import ObjectId
from datetime import datetime
class MongoengineEncoder(json.JSONEncoder):
"""
The default JSON encoder that ships with Mongoengine (the to_json method
exposed on Document instances) makes some odd choices. Datetime objects
are nested on a $date property, ObjectIds are nested on an $oid property,