Skip to content

Instantly share code, notes, and snippets.

View sytranvn's full-sized avatar
(n)

Sy Tran Dung sytranvn

(n)
View GitHub Profile
@sytranvn
sytranvn / what-forces-layout.md
Created December 7, 2017 10:43 — forked from paulirish/what-forces-layout.md
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Element

Box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
  • elem.clientLeft, elem.clientTop, elem.clientWidth, elem.clientHeight
  • elem.getClientRects(), elem.getBoundingClientRect()
@sytranvn
sytranvn / setuid-root-backdoor.md
Created December 14, 2017 14:15 — forked from dergachev/setuid-root-backdoor.md
How to use setuid to install a root backdoor.

Why You Can't Un-Root a Compromised Machine

Let's say somebody temporarily got root access to your system, whether because you "temporarily" gave them sudo rights, they guessed your password, or any other way. Even if you can disable their original method of accessing root, there's an infinite number of dirty tricks they can use to easily get it back in the future.

While the obvious tricks are easy to spot, like adding an entry to /root/.ssh/authorized_keys, or creating a new user, potentially via running malware, or via a cron job. I recently came across a rather subtle one that doesn't require changing any code, but instead exploits a standard feature of Linux user permissions system called setuid to subtly allow them to execute a root shell from any user account from the system (including www-data, which you might not even know if compromised).

If the "setuid bit" (or flag, or permission mode) is set for executable, the operating system will run not as the cur

Let's say you're editing a file in VIM, and want to see a diff between your current unsaved version and what's on the hard disk. Turns out you can just type this:

:w !git diff --no-index % -

What this does it pipes the whole contents of the current file to the command git diff --no-index % - The % symbol is substituted by vim to be the path to the saved file. The - tells git diff to read from STDIN.

@sytranvn
sytranvn / example.js
Created December 14, 2017 19:37 — forked from grind086/example.js
Adding data to NaN values
console.log(examineNaN(NaN));
// > { isNaN: true, sign: 0, signaling: false, payload: 0 }
const nan = createNaN(false, false, 5000);
console.log(isNaN(nan));
// > true
console.log(examineNaN(nan));
// > { isNaN: true, sign: 0, signaling: false, payload: 5000 }
const nan2 = createNaN(false, false, [1, 2, 3, 4, 5, 6]);
@sytranvn
sytranvn / redux-logger.js
Last active January 30, 2018 21:02
Simple middle ware to log redux actions
import { createStore, applyMiddleware } from 'redux'
import thunk from 'redux-thunk'
const logger = ({ getState, dispatch }) => next => action => {
console.group && console.group(action.type)
log.info('%c prev state\n', 'color: gray', getState().toJS())
log.info('%c action\n', 'color: blue', action)
const returnValue = next(action)
log.info('%c next state\n', 'color: red', getState().toJS())
console.group && console.groupEnd(action.type)
@sytranvn
sytranvn / revert-a-commit.md
Created March 12, 2018 09:56 — forked from gunjanpatel/revert-a-commit.md
Git HowTo: revert a commit already pushed to a remote repository

Revert the full commit

Sometimes you may want to undo a whole commit with all changes. Instead of going through all the changes manually, you can simply tell git to revert a commit, which does not even have to be the last one. Reverting a commit means to create a new commit that undoes all changes that were made in the bad commit. Just like above, the bad commit remains there, but it no longer affects the the current master and any future commits on top of it.

git revert {commit_id}'

About History Rewriting

Delete the last commit

Deleting the last commit is the easiest case. Let's say we have a remote origin with branch master that currently points to commit dd61ab32. We want to remove the top commit. Translated to git terminology, we want to force the master branch of the origin remote repository to the parent of dd61ab32:

@sytranvn
sytranvn / Benchmark.py
Created March 19, 2018 02:18
Benchmark
def method_counter(func):
@wraps(func)
def wrapper(self, *args, **kwargs):
start_time = time.time()
value = func(self, *args, **kwargs)
print("api: {} {}".format(args[0], args[1]))
print("-------------------- %s seconds ---------------------------" % (time.time() - start_time))
return value
return wrapper
@sytranvn
sytranvn / subTest
Created March 19, 2018 04:39 — forked from encukou/subTest
Python 3.4. subTest example
This is a comment on http://eli.thegreenplace.net/2014/04/02/dynamically-generating-python-test-cases/
@sytranvn
sytranvn / event.js
Created April 20, 2018 03:51
Dispatch an event that works on Android
export function dispatchNewEvent(eventName, target) {
let event;
try {
event = new Event(eventName, {
bubbles: true,
});
} catch (e) {
event = document.createEvent('Event');
event.initEvent(eventName, true, false);
}