Skip to content

Instantly share code, notes, and snippets.

@zbicin
zbicin / FocusOnDirective.js
Created August 1, 2015 18:35
Directive focusing an element when given scope variable becomes boolean true.
/*
* Directive focusing an element when given scope variable becomes boolean true.
* If the variable becomes equal to boolean false the element is blurred.
* Usage: <input type="text" focus-on="someScopeVariable === 1" />
*/
angular.module('FocusOnDirective').directive('focusOn', ['$timeout', function ($timeout) {
'use strict';
return {
restrict: 'A',
@zbicin
zbicin / parseUrlParameters.js
Created October 15, 2015 19:58
A snippet serving URL parameters as an object
function parseUrlParameters() {
var result = {};
var keyValueCombined = location.search.substr(1).split('&');
for(var i = 0; i<keyValueCombined.length; i++) {
var splitted = keyValueCombined[i].split('=');
var key = splitted[0];
var value = splitted.slice(1).join('=');
result[key] = value;
}
@zbicin
zbicin / damnHandler.js
Created December 17, 2017 08:48
Damn error handler
function damnHandler(e) {
console.log('%c.', 'font-size: 1px; line-height: 140px; padding: 70px 125px; background: url("https://media.giphy.com/media/r1HGFou3mUwMw/giphy-downsized.gif");');
throw e;
}
#!/bin/bash
tap ()
{
adb shell sendevent /dev/input/event1 3 57 9148
adb shell sendevent /dev/input/event1 3 53 $1
adb shell sendevent /dev/input/event1 3 54 $2
adb shell sendevent /dev/input/event1 3 58 54
adb shell sendevent /dev/input/event1 0 0 0
adb shell sendevent /dev/input/event1 3 57 -1
adb shell sendevent /dev/input/event1 0 0 0
@zbicin
zbicin / copyJson.user.js
Created June 28, 2018 09:40
A userscript that adds copyJson method to the window object.
// ==UserScript==
// @name copyJson
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Stringifies given argument and copies it to the clipboard.
// @author @zbicin
// @match *://localhost*/*
// @grant none
// ==/UserScript==
@zbicin
zbicin / README.md
Last active February 12, 2019 16:16
Copy VSTS Pull Request branch to clipboard

How to use?

  1. Copy the contents below *:
(function(){const copyText=(text)=>{const textField=document.createElement('textarea');textField.innerText=text;document.body.appendChild(textField);textField.select();document.execCommand('copy');textField.remove()};const branchLinks=document.querySelectorAll('.ms-Link.vc-pullrequest-detail-branch-name, .vc-branches-container .vss-PickListDropdown--title-text');if(branchLinks.length<1){alert('Branch link not found')}else{const branchName=branchLinks[0].innerText.trim();copyText(branchName);const oldTitle=document.title;document.title=`📋 Copied: "${branchName}"`;setTimeout(()=>document.title=oldTitle,1000)}})()
  1. Create a new bookmark and paste the contents as URL.
  2. Done. We can call it a day.
@zbicin
zbicin / pb.sh
Created May 3, 2019 12:56
Send Pushbullet notification from CLI
#!/bin/bash
# Source: https://danielgibbs.co.uk/2016/06/send-pushbullet-message-from-bash/
token="<paste token here>"
title=${1:-Default title}
body=${2:-Default body}
curl --silent -u """$token"":" -d type="note" -d body="$body" -d title="$title" 'https://api.pushbullet.com/v2/pushes'
@zbicin
zbicin / Instalacja Node.js na Windows, Linuksie i MacOS.md
Last active May 1, 2024 20:22
Instalacja Node.js na Windows, Linuksie i MacOS

Instalacja Node.js na Windows, Linuksie i MacOS

Najprostszym i najpewniejszym sposobem na bezproblemową instalację Node.js jest użycie NVM (Node Version Manager), który pobierze za nas odpowiednią paczkę, zainstaluje ją i ustawi poprawnie wszystkie systemowe ścieżki.

Windows

  1. Pobieramy spakowany instalator z GitHuba projektu nvm-windows:

https://github.com/coreybutler/nvm-windows/releases/download/1.1.7/nvm-setup.zip

@zbicin
zbicin / curl.md
Created November 22, 2019 18:04
cURL cheatsheet

GET

curl http://localhost:3000/messages

POST (JSON)

curl -d '{"login": "zbicin", "message": "test message"}' -H "Content-Type: application/json" -X POST http://localhost:3000/sendMessage
@zbicin
zbicin / server.js
Created November 23, 2019 13:43
server.js 2
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const readline = require('readline');
const childProcess = require('child_process');
const https = require('https');
const app = express();
if (process.argv.includes('--prompt')) {