Skip to content

Instantly share code, notes, and snippets.

@frnkst
frnkst / online.sh
Last active July 24, 2017 10:36
Check if you are online or not
#!/bin/bash
wget -q --spider http://google.com
if [ $? -eq 0 ]; then
echo "Online"
else
echo "Offline"
fi
@frnkst
frnkst / protractor_test.js
Last active July 24, 2017 10:38
Delay protractor clicks
// put it on top of the file, not in a describe block
// it delays protractor actions by 100ms so you can see
// what's happening
var origFn = browser.driver.controlFlow().execute;
browser.driver.controlFlow().execute = function() {
var args = arguments;
// queue 100ms wait
origFn.call(browser.driver.controlFlow(), function() {
@frnkst
frnkst / prepare-commit-msg
Last active February 26, 2019 09:23
Add the branch name in uppercase at the beginning of your commit messages
#!/usr/local/bin/bash
# Instructions: Rename .git/hooks/prepare-commit-msg.sample to
# .git/hooks/prepare-commit-msg and add the contents of this file.
# Make the file executable by typing "chmod u+x .git/hooks/prepare-commit-msg"
# This way you can customize which branches should be skipped when
# prepending commit message.
if [ -z "$BRANCHES_TO_SKIP" ]; then
BRANCHES_TO_SKIP=(master develop test)
@frnkst
frnkst / angular_service_from_dev_console.js
Last active January 22, 2018 13:41
Angular service from developer console
// Replace $window with any other injected service
var win = angular.element(document.querySelector('html')).injector().get('$window');
// Or access the scope over a DOM element (fix .the-css-class and ctrlName. Maybe $parent is not needed either
var a = angular.element('.the-css-class').scope().$parent.ctrlName;
@frnkst
frnkst / ThirdPartyNoticesExample.md
Created September 1, 2017 09:41 — forked from Radagaisus/ThirdPartyNoticesExample.md
Markdown Table from Yarn Licenses (YMMV)
@frnkst
frnkst / pre-commit
Created March 19, 2018 15:34
Run eslint on all staged files before committing
#!/bin/bash
for file in $(git diff --diff-filter=d --cached --name-only | grep -E '\.js$')
do
git show ":$file" | node_modules/.bin/eslint --stdin --stdin-filename "$file" # we only want to lint the staged changes, not any un-staged changes
if [ $? -ne 0 ]; then
echo "ESLint failed on staged file '$file'. Please check your code and try again."
exit 1 # exit with failure status
fi
done
@frnkst
frnkst / M1.js
Last active July 1, 2018 16:55
Medium Import
const dgram = require('dgram');
const raw = require('raw-socket');
const dns = require('dns-then');
const icmpSocket = raw.createSocket({ protocol: raw.Protocol.ICMP });
const udpSocket = dgram.createSocket('udp4');
@frnkst
frnkst / M2.js
Last active June 19, 2018 11:29
M2
function sendPacket() {
port++;
if (tries >= 3) {
tries = 0;
ttl++;
}
tries++;
udpSocket.setTTL(ttl);
icmpSocket.on('message', async function (buffer, ip) {
let p = buffer.toString('hex').substr(100, 4);
let portNumber = parseInt(p, 16);
if (port === portNumber) {
try {
let symbolicAddress;
if (!NO_REVERSE_LOOKUP) {
symbolicAddress = await getSymbolicAddress(ip);
}
handleReply(ip, symbolicAddress)[0];
function handleReply(ip, symbolicAddress) {
if (timeout) {
clearTimeout(timeout);
}
if (ip) {
const elapsedTime = `${(process.hrtime(startTime)[1] / 1000000).toFixed(3)} ms`;
if (ip === previousIP) {
process.stdout.write(` ${elapsedTime}`);