Skip to content

Instantly share code, notes, and snippets.

View jcubic's full-sized avatar
🎯
Focusing

Jakub T. Jankiewicz jcubic

🎯
Focusing
View GitHub Profile
@jcubic
jcubic / javascript query string
Last active October 6, 2015 13:58
create an object from query string
var query = (function() {
function decode(string) {
return decodeURIComponent(string.replace(/\+/g, " "));
}
var result = {};
if (location.search) {
location.search.substring(1).split('&').forEach(function(pair) {
pair = pair.split('=');
result[decode(pair[0])] = decode(pair[1]);
});
@jcubic
jcubic / jquery hackerrank bot
Created July 2, 2012 21:12
Bot that hack hackerrank interface to solve game
(function() {
function enter(element, string) {
var prompt = $(element);
var press = jQuery.Event("keydown");
press.which = 13;
press.keyCode = 13;
prompt.val(string).trigger(press);
}
function move(count) { // number of moves
@jcubic
jcubic / gist:3113708
Created July 14, 2012 22:32
Javascript bot that solve 2 challange on Hacker Rank
(function() {
function DoCaeserEncrypt(x,shf){
var abc="abcdefghijklmnopqrstuvwxyz";
var ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var r1="";
var r2="";
var shf=eval(shf);
for(i=0;i < x.length;i++){let=x.charAt(i);pos=ABC.indexOf(let);if(pos >=0){r1+=ABC.charAt( (pos+shf)%26 )}else{r1+=let};};
for(i=0;i < r1.length;i++){let=r1.charAt(i);pos=abc.indexOf(let);if(pos >=0){r2+=abc.charAt( (pos+shf)%26 )}else{r2+=let};};
return r2;
@jcubic
jcubic / gist:3113713
Created July 14, 2012 22:35
Candy Game challage on Hacker Rank
(function(start) {
function send(method, data, fun) {
$.ajax({
type: method,
url: '/splash/challenge.json',
dataType: 'json',
data: data,
success: fun
});
}
@jcubic
jcubic / gist:3162477
Created July 23, 2012 07:55
breaking forEach loop in javascript
(function(continuation) {
[1,2,3,4].forEach(function(e, i) {
if (e == 2) {
continuation();
}
});
})(function() {
// rest of the code
});
@jcubic
jcubic / gist:3194755
Created July 28, 2012 20:55
Javascript obfuscation challange
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('1Q(1m(1m("1Q(3B(p%3k%3g%1u%3c%3b)%39%1J(c)%1k(c%35%2V\'\'%2U(2T(c%2P)))%1h((c%2L%2K)%2J%2I.2H(c%2G)%2F.2E(36))%S%2D(!\'\'.1w(%1y%2C%1y%2A))%2y(c--)r%1F(c)%Q%2x%1c%Q%W%2v(c)%2t%2s%2r(e)%1k%2p%1F%Q%S%Q%2n%1J()%1k\'%1b%2j%1h\'%S%2i%2g%S%2f(c--)2e(k%1c%Q)p%2d.1w(2c%2b(\'%1b%1x\'%2a(c)%1h\'%1b%1x\'%19\'g\')%1u%1c%Q)%29%28%S(\'1L(13(13(13(%27%24%1l%23%f%J%u%l%A%2%7%0%22%0%n%0%w%0%1p%0%y%0%x%7%4%7%0%1t%0%w%0%16%0%n%0%21%0%20%0%1j%7%4%7%0%x%0%m%0%n%0%1j%7%4%7%0%y%0%M%0%8%j%0%M%0%11%0%n%0%m%0%1Z%0%1E%0%N%0%n%7%4%7%0%O%0%N%0%n%0%m%0%8%F%0%1p%0%n%0%w%0%y%7%4%7%0%x%0%y%0%y%0%s%0%8%z%0%10%0%10%0%T%0%14%0%1O%0%Y%0%14%0%1Y%0%Y%0%14%0%1X%0%14%0%Y%0%14%0%1W%0%1O%0%10%0%48%0%T%7%4%7%0%x%0%y%0%y%0%s%7%4%7%0%
@jcubic
jcubic / gist:3426536
Created August 22, 2012 15:05
185 bytes bookmarklet that insert javascript file into page
javascript:(function(a,s){s[a]('src',prompt());s[a]('type','text/javascript');document.getElementsByTagName('head')[0].appendChild(s);})('setAttribute',document.createElement('script'))
@jcubic
jcubic / gist:3518347
Created August 29, 2012 20:21
log list of YouTube id and titles from playlist
console.log(Array.prototype.slice.call(document.querySelectorAll('.playlist-landing ol li a')).map(function(a) { return a.getAttribute('href').match(/(v=[^&]+)/)[1] + ' ' + a.innerHTML.match(/(class="title.*?)<\/span>/)[1].replace(/.*>/,''); }).join("\n"))
@jcubic
jcubic / gist:3729817
Created September 15, 2012 21:17
Restore functions from console
c=console;for(var i in c.__proto__){(function(i){c[i]=function(){c.__proto__[i].apply(c,[].slice.call(arguments));};})(i);}
@jcubic
jcubic / README.md
Created September 16, 2012 13:30
Print missing html entities from XML file in DOCTYPE ready to paste format

Description

Command Line that print entities (like & or ") in way that can be paste into <!DOCTYPE if xml file don't define them and parser return error, that entity is not defined. Command check if Entity is not already defined.