Skip to content

Instantly share code, notes, and snippets.

View dvlden's full-sized avatar
🧨
I am the error that you should catch!

Nenad Novaković dvlden

🧨
I am the error that you should catch!
View GitHub Profile
@dvlden
dvlden / snippet.js
Last active September 11, 2017 17:05
ITAcademy/LinkLearning - Skip time waiting on lessons
(function ($) {
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
@dvlden
dvlden / snippet.js
Last active September 11, 2017 17:06
Load any Script files - The asynchronous way
/* Example of how to load Facebook SDK */
loadAsync(document, 'script', '//connect.facebook.net/en_US/sdk.js', 'facebook-jssdk', successCallback);
function successCallback () {
console.log('Facebook\'s SDK successfully loaded.');
}
/* Asynchronously load any script files */
function loadAsync ( doc, elem, source, id, cb ) {
var ready = false,
@dvlden
dvlden / .htaccess
Last active September 11, 2017 17:06
Pretty URL's are always nice and great in many cases. This is how you rewrite your URL's to remove / strip off php extension
<IfModule mod_rewrite.c>
# remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} \s(.+?)/+[?\s]
RewriteRule ^(.+?)/$ /$1 [R=301,L]
# To externally redirect /dir/file.php to /dir/file
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]
@dvlden
dvlden / snippet.html
Last active September 11, 2017 17:09
Open link(s) in small browser dialog or new tab on phones/tablets
<a
href="https://google.com"
onClick="return popThis(this.href, 500, 370)">
Open Google
</a>
@dvlden
dvlden / dummy.js
Created October 14, 2017 13:42
Some JS Testing...
const getSiblings = element => {
let siblings = []
let sibling = element.parentNode.firstChild
while (sibling = sibling.nextSibling) {
if (sibling.nodeType === 1 && sibling !== element) {
siblings.push(sibling)
}
}
@dvlden
dvlden / index.js
Created April 10, 2018 18:23
Just testing the "call, apply and bind"...
// I never really understood them, but now I think I got it...
let anObject = {
name: 'Nenad',
age: 25
};
let myArguments = ['Serbia', 'Valjevo', 'in a relationship'];
let anFunction = function (country, city, relationshipStatus) {
@dvlden
dvlden / index.js
Created August 5, 2018 16:14
MutationObserver in JavaScript
/**
* Sometimes, an element that you might need to retrieve
* is not visible right away. It might be added later on
* via an asynchronous action.
*
* This is where MutationObserver in JS comes in
* and here you can learn from example.
*
* Example will retrieve video element from the web page.
*/
@dvlden
dvlden / macOS - Terminal.md
Last active September 8, 2018 05:08
I tried to simplify all the keystrokes / shortcuts and common terminal commands that I use daily myself... I hope it helps anyone, spent too much time writing this.

Don’t be afraid of Terminal on any OS, let me simplify things for you! I’ve been using Terminal a lot lately, yet I remember the time when I was entirely afraid of even typing anything in it...

Whenever I needed something on my Mac, that required Terminal commands, I had a tough time figuring what does it mean, how does it work; especially when it's a very long one. Well, it was worth it, not just copy/pasting the command, seeing it works and continuing with my day.


Key Representation

VISUAL KEY DESCRIPTIVE KEY
@dvlden
dvlden / 1.js
Last active April 13, 2019 22:03
JavaScript Algorithm
// Find missing numbers in the array
const numbers = [1, 2, 7, 3, 5, 4, 9]
let missing = []
for (var i = 1; i <= Math.max(...numbers); i++) {
if (!numbers.includes(i)) {
missing.push(i)
}
}
@dvlden
dvlden / extract-cookies.php
Last active September 25, 2023 13:49
Quickly Extract "Netscape HTTP Cookie File" to "JSON" (from ".txt" to ".json" format)
<?php
function extractCookies ($string) {
$cookies = array();
$lines = explode("\n", $string);
// iterate over lines
foreach ($lines as $line) {
// we only care for valid cookie def lines