Skip to content

Instantly share code, notes, and snippets.

View achudars's full-sized avatar
🥔
every challenge is an opportunity

Aleks achudars

🥔
every challenge is an opportunity
View GitHub Profile
@achudars
achudars / web-snippet-051 ( Web Scraper in PHP )
Last active December 17, 2015 03:29
A Web Scraper in PHP to get points, completed courses and attended events from Microsoft Virtual Academy (MVA). It depends on SIMPLE HTML DOM PARSER. Also you need to make sure that in PHP settings allow_url_fopen and allow_url_include flags are set to ON, and you must have these extensions selected: php_openssl and php_curl .
<!--
Use this code as you please!
The most important bit is passing the $id as a string.
As long as you know the id, you can get the info you need.
Note: It is quite slow (at least for me)!
As there are more than a million people in Microsoft Virtual Academy,
you could pass a random id in that range and see what you get! =)
-->
@achudars
achudars / web-snippet-050 ( String.endsWith in JavaScript )
Last active December 17, 2015 00:19
Use of String.endsWith in JavaScript
var str = "To be, or not to be, that is the question.";
alert( str.endsWith("question.") ); // true
alert( str.endsWith("to be") ); // false
alert( str.endsWith("to be", 19) ); // true
@achudars
achudars / web-snippet-049 ( rest parameters in JavaScript )
Last active December 17, 2015 00:19
Use of rest parameters in JavaScript
function fun1(...theArgs) {
console.log(theArgs.length);
}
fun1(); // 0
fun1(5); // 1
fun1(5, 6, 7); // 3
@achudars
achudars / web-snippet-048 ( 'for ... of' in JavaScript )
Last active December 17, 2015 00:19
Use of 'for ... of' in JavaScript
let arr = [ 3, 5, 7 ];
arr.foo = "hello";
for (let i in arr) {
console.log(i); // logs "0", "1", "2", "foo"
}
for (let i of arr) {
console.log(i); // logs "3", "5", "7"
}
@achudars
achudars / web-snippet-047 ( Matches-any pseudo-class in CSS )
Last active December 17, 2015 00:19
Matches-any pseudo-class in CSS
section h1, article h1, aside h1 {
color: red;
}
/* Is the same as */
:matches(section, article, aside) h1 {
color: red;
}
@achudars
achudars / web-snippet-046 ( Negation pseudo-class in CSS )
Last active December 17, 2015 00:19
Negation pseudo-class in CSS
a:not([rel="external"], [rel="nofollow"]) {
color: red;
}
@achudars
achudars / web-snippet-045 ( Page redirection in CakePHP )
Last active December 17, 2015 00:19
Page redirection in CakePHP
$this->redirect('/admin/index'); //Simple
$urldata = $this->Session->read('manageadminuserpage'); //Redirecting to Session stored url.
$this->redirect($urldata);
@achudars
achudars / web-snippet-044 ( Check if a website is a spoof )
Last active December 17, 2015 00:19
Check if a website is a spoof. Paste it in the console while visiting a website.
javascript:alert("The actual URL is:\t\t" + location.protocol + "//" + location.hostname + "/" + "\nThe address URL is:\t\t" + location.href + "\n" + "\nIf the server names do not match, this may be a spoof.");
@achudars
achudars / web-snippet-043 ( Selection colour using CSS )
Last active December 17, 2015 00:19
Selection colour using CSS
::selection {background:#ffb7b7;color: #FFF}
::-moz-selection {background:#ffb7b7;color:#FFF}
@achudars
achudars / web-snippet-042 ( Password Strength testing in jQuery )
Last active December 17, 2015 00:19
Password Strength testing using jQuery
// jQuery:
$('#pass').keyup(function(e) {
var strongRegex = new RegExp("^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$", "g");
var mediumRegex = new RegExp("^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g");
var enoughRegex = new RegExp("(?=.{6,}).*", "g");
if (false == enoughRegex.test($(this).val())) {
$('#passstrength').html('More Characters');
} else if (strongRegex.test($(this).val())) {
$('#passstrength').className = 'ok';