Skip to content

Instantly share code, notes, and snippets.

View sneas's full-sized avatar
🇺🇦

Dimah Snisarenko sneas

🇺🇦
View GitHub Profile
@premek
premek / mv.sh
Last active March 5, 2024 17:43
Rename files in linux / bash using mv command without typing the full name two times
# Put this function to your .bashrc file.
# Usage: mv oldfilename
# If you call mv without the second parameter it will prompt you to edit the filename on command line.
# Original mv is called when it's called with more than one argument.
# It's useful when you want to change just a few letters in a long name.
#
# Also see:
# - imv from renameutils
# - Ctrl-W Ctrl-Y Ctrl-Y (cut last word, paste, paste)
@evxn
evxn / do-on-subscribe.rxjs.operator.ts
Last active March 5, 2021 17:26
rxjs on subscribe hook, callback on subscribe, doOnSubscribe operator, doOnSubscribe pipe, rxjs onSubscribe
import {defer} from 'rxjs/observable/defer';
import {Observable} from 'rxjs/Observable';
/** Example
import {from} from 'rxjs/observable/from';
from([1, 2, 3])
.pipe(doOnSubscribe(() => console.log('subscribed to stream')))
.subscribe(x => console.log(x), null, () => console.log('completed'));
*/
const l = () => {
// tslint:disable-next-line:one-variable-per-declaration
const stack = new Error().stack,
caller = stack.split('\n')[2].trim();
let args = Array.prototype.slice.call(arguments);
console.log.apply(this, [caller, args]);
};
const i = () => {
// tslint:disable-next-line:one-variable-per-declaration
@oleksii-zavrazhnyi
oleksii-zavrazhnyi / gist:968e5ea87e99d9c41782
Created November 28, 2014 17:32
BASH Absolute path of current script
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )

Is a useful one-liner which will give you the full directory name of the script no matter where it is being called from

These will work as long as the last component of the path used to find the script is not a symlink (directory links are OK). If you want to also resolve any links to the script itself, you need a multi-line solution:

SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
@mathiasbynens
mathiasbynens / .gitignore
Last active August 7, 2024 02:26
Generating a regular expression to match valid JavaScript identifiers (like https://mathiasbynens.be/demo/javascript-identifier-regex) in Node.js
package-lock.json
node_modules