Skip to content

Instantly share code, notes, and snippets.

@ajhsu
ajhsu / .tmux.conf
Created November 3, 2018 06:22 — forked from jikkujose/.tmux.conf
Change prefix key in tmux to back-tick and still type back-ticks
unbind C-b
set-option -g prefix `
bind ` send-prefix
@ajhsu
ajhsu / memorySizeOfObject.js
Last active October 23, 2018 02:44 — forked from dohoons/memorySizeOfObject.js
calculate memory size of javascript object, it is not a accurate value!
function memorySizeOf(obj) {
let bytes = 0;
function sizeOf(obj) {
if (obj !== null && obj !== undefined) {
switch (typeof obj) {
case 'number':
bytes += 8;
break;
case 'string':
@ajhsu
ajhsu / diff-pdf-files.md
Last active September 6, 2018 10:42 — forked from thbar/how-to-diff-pdf-files-with-git-and-diffpdf.md
How to diff PDF files with Git

One can use MD5 or plain text diff to see differences in PDF files. If that's not enough, here's how to use diffpdf which knows how to diff based on appearance or words:

  • brew install diff-pdf
  • edit your ~/.gitconfig to add this:
[difftool "diffpdf"]
  cmd = diff-pdf \"$LOCAL\" \"$REMOTE\"
@ajhsu
ajhsu / adb-commands
Last active August 16, 2018 06:28 — forked from Pulimet/AdbCommands
adb useful commands list
## Adb Server
adb kill-server
adb start-server
## Adb Reboot
adb reboot
adb reboot recovery
adb reboot-bootloader
## Shell
@ajhsu
ajhsu / index.js
Created May 31, 2018 09:28 — forked from maskit/gist:2252422
WebSocket traffic sniffer
(function() {
WebSocket.prototype.realSendFunc = WebSocket.prototype.send;
WebSocket.prototype.send = function(data) {
this.realSendFunc(data);
this.addEventListener('message', function(msg) {
console.log('>> ' + msg.data);
}, false);
this.send = function(data) {
this.realSendFunc(data);
console.log("<< " + data);
@ajhsu
ajhsu / open-iterm-from-finder.md
Created April 27, 2018 03:07 — forked from jonschlinkert/open-iterm-from-finder.md
Add an icon to your finder toolbar to open iTerm in the current folder.

Open iTerm from finder

The code and instructions in this gist are from http://peterdowns.com/posts/open-iterm-finder-service.html. I've had to do this a few times and wanted to distill it the basics.

  1. Open Automator
  2. Create an Application
  3. Choose Actions > Utilities > Run Applescript
  4. Paste the contents of open_in_iterm.app into the window.
  5. Save the script somewhere convenient
  6. Find the script, then drag the script onto the Finder window while holding the command key (or in Yosemite, the command + option keys)
@ajhsu
ajhsu / xmlhttprequest-mitm-attack.js
Last active April 4, 2023 14:43 — forked from jasperck/XHRMITM.js
To intercept and modify the response, browser could render with your mutation
const responseTransform = requestURL => response => {
// Original request url
console.log(requestURL);
// Deep clone from response
const nextResponse = JSON.parse(JSON.stringify(response));
// do what you want with response
if (nextResponse.results_json) {
nextResponse.results_json.search_results.map(r => {
r.listing.name = '顆顆';
});
@ajhsu
ajhsu / better-nodejs-require-paths.md
Created October 28, 2015 04:15 — forked from branneman/better-nodejs-require-paths.md
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

var Article = require('../../../models/article');

Those suck for maintenance and they're ugly.

Possible solutions