Skip to content

Instantly share code, notes, and snippets.

View CezaryDanielNowak's full-sized avatar

Cezary Nowak CezaryDanielNowak

  • Testucan
  • Warsaw, Poland
View GitHub Profile
@CezaryDanielNowak
CezaryDanielNowak / highlightTextInDomNode.js
Last active August 29, 2015 14:16
I had to remove this from project, that I am working on, but it's still a bit of useful code.
var highlightTextInDomNode = function(text, targetNode, highlightColor) {
// summary:
// This function takes any domNode, and highlight given text.
// text: String
// Text to highlight
// domNode: domNode
// DomNode to search text
if(!text || !targetNode) {
return;
}
@CezaryDanielNowak
CezaryDanielNowak / node-parse-argv
Last active August 29, 2015 14:17
Simple tool to parse process.argv.
/*
Sample usage:
node ./index.js port=80 pathToServe=../frontend/_public_prod
*/
require('es6-shim'); // Object.assign needs es6
var parseArgv = function(options, argv) {
argv || (argv = Array.prototype.slice.call(process.argv, 2));
var result = {};
@CezaryDanielNowak
CezaryDanielNowak / getNested
Created April 30, 2015 11:20
lodash/underscore is required
var getNested = function(object, nestedKeys, separator) {
// summary:
// `obj.data.nested.callback()` throws error, when some of parent objects aren't available
// `if(obj && obj.data && obj.data.nested && obj.data.nested.callbac) { obj.data.nested.callbac() }` is ugly.
// object: Object
// Object to seek in
// nestedKeys: String
// Path for obj
// example:
// getNested(obj, 'you.better.stahp');
@CezaryDanielNowak
CezaryDanielNowak / find-text-in-xhr.js
Last active August 29, 2015 14:26
Thousand of backend requests, and you don't know, where is the source of data? Just add this to your <head> or greasemonkey.
(function() {
var lookForText = "rocess for the production of a fine chemical";
var send = XMLHttpRequest.prototype.send;
var transferComplete = function (e) {
var text = e.responseText || e.target.responseText;
var url = e.responseURL || e.target.responseURL;
if(text && text.indexOf(lookForText) !== -1) {
console.info("|FOUND IT!|", e, url);
} else {
console.info("|Looking for it...|", e);
@CezaryDanielNowak
CezaryDanielNowak / greasemonkey-joke.js
Created October 14, 2015 10:37
If someone is not signed off, install greasemonkey and put this script to all websites (*)
// 10% page loads, flip random element vertically
if (Math.random() < 0.1) {
var all = document.body.querySelectorAll('*');
all[parseInt(Math.random()*all.length, 10)].style.transform = 'rotate(180deg)'
}
// ==UserScript==
// @name Aero2: Go to captcha and redirect to router
// @namespace aero2
// @include http://bdi.free.aero2.net.pl:8080/
// @version 1
// @grant none
var __routerUsername = 'admin';
var __routerPassword = 'password';
# same as git branch -l but sorts by date
git config --global alias.bl "for-each-ref --sort=-committerdate refs/heads/"
git config --global alias.cb "checkout --track -b"
# make sure if you use ", not '
# to be continued
@CezaryDanielNowak
CezaryDanielNowak / gist:5048861
Last active December 14, 2015 07:09
auto-fill form by javascript console.
$($0 || 'body').find('input[type=text], input[type=text], textarea,input[type=password]').filter(':visible').each(function(){
if( $(this).attr('type')==='password' )
return $(this).val('12345678');
if( $(this).attr('id')==='email' || $(this).attr('name')==='email' )
return $(this).val('some@email.com');
if( $(this).attr('name') == 'cvv2' )
return $(this).val('123');
@CezaryDanielNowak
CezaryDanielNowak / windows-command-line-helpers-generator
Last active December 16, 2015 13:29
Window commands. Put it in:c:\windows\system32\or add yours include path.
echo @dir /O:G %* > ls.bat
copy /A ls.bat ll.bat
echo C:\wamp\bin\php\php5.3.13\php.exe %* > php.bat
echo php "C:\wamp\bin\php\php5.3.13\composer.phar" %* > composer.bat
echo ipconfig | find "Adres IPv4" > myip.bat
echo @for %%e in (%PATHEXT%) do @for %%i in (%1%%e) do @if NOT "%%~$PATH:i"=="" echo %%~$PATH:i > whereis.bat
jQuery.fn.loadSerializedData = function(data)
{
var dataObj = {},
keyValPair;
data = data.split('&');
for (var i = 0, length = data.length; i < length; i++) {
keyValPair = data[i].split('=');
dataObj[decodeURIComponent(keyValPair[0])] = decodeURIComponent(keyValPair[1]);
}