Skip to content

Instantly share code, notes, and snippets.

View marcus-at-localhost's full-sized avatar
💭
☕

Marcus marcus-at-localhost

💭
☕
View GitHub Profile
@marcus-at-localhost
marcus-at-localhost / info.md
Last active December 26, 2016 11:57 — forked from eltonmesquita/onViewport.js
A simple jQuery function that adds a class when the target(s) is in the viewport

Use like this:

// Call the function with the following parameters:
onViewport(selector, classNameToBeAdded, offset, callback);

// Example:
onViewport(".about-section", "active", 300, function() {
  console.log("This is not a drill.")
});
("0" + h).slice (-2); // devolverá "01" si h=1; "12" si h=12
("00" + h).slice (-3); // "001" si h=1; "012" si h=12;"123" si h = 123
@marcus-at-localhost
marcus-at-localhost / random-integer.js
Last active December 26, 2016 19:03
Random Integer Range `getRandomInt(5, 10)// -> 5, 8, 6, 10` http://stackoverflow.com/a/24152886/814031
// Returns a random integer between min (included) and max (included)
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
getRandomInt(5, 10); // -> 5, 8, 6, 10
@marcus-at-localhost
marcus-at-localhost / check-for-variable.js
Last active April 25, 2018 19:37
Check for variables in JavaScript
var data = {'foo': 'bar'};
if(data.hasOwnProperty("foo")){
console.log(data.foo);
}
if(typeof data == 'object'){
//console.log(e)
}
@marcus-at-localhost
marcus-at-localhost / 01-flatten-object.js
Last active December 27, 2016 22:12
Flatten an object
var flattenObject = function(ob) {
return Object.keys(ob).reduce(function(toReturn, k) {
if (Object.prototype.toString.call(ob[k]) === '[object Date]') {
toReturn[k] = ob[k].toString();
}
else if ((typeof ob[k]) === 'object' && ob[k]) {
var flatObject = flattenObject(ob[k]);
Object.keys(flatObject).forEach(function(k2) {
.mixin (@width,@height,@x,@y) {
width: @width*1px;
height: @height*1px;
margin: @x*(-1px) @y*(-1px);
}
.element{
.mixin(100,100,25,25);
}
@marcus-at-localhost
marcus-at-localhost / bookmarklet.js
Last active November 9, 2019 01:51
[Markdown Quote from Website - Bookmarklet] Select text, click the bookmarklet, get an overlay with the selection styled as Markdown quote with source, click "copy" to get the selection copied to your clipboard.Uses https://github.com/zenorocha/clipboard.js
/**
* Markdown Quote to Clipboard
*/
var mo = {
version: 1,
btnId: 'clipboard-btn-dceaeae8-1557-4454-883c-05ae99312192',
id:'clipboard-dceaeae8-1557-4454-883c-05ae99312192',
textareaId: 'clipboard-textarea-dceaeae8-1557-4454-883c-05ae99312192',
uniqueId: 'clipboard-script-dceaeae8-1557-4454-883c-05ae99312192',
@marcus-at-localhost
marcus-at-localhost / target-blank.js
Last active November 1, 2017 15:26
[Add Attributes to All Links] Add target="_blank" to all links in HTML document, unless it's an internal page link. Want to keep the pagerank for yourself? Throw in a rel="nofollow" (php only) http://ideone.com/bqwdsk / http://jsbin.com/vurimiguci/edit?html,js,console,output #dom
// http://jsbin.com/vurimiguci/edit?html,js,console,output
var links = document.querySelectorAll( 'a' );
for (var i = 0, l = links.length; i < l; i++) {
if (links[i].hostname != window.location.hostname) {
links[i].target = '_blank';
}
}
@marcus-at-localhost
marcus-at-localhost / pug-whitespace.md
Last active November 1, 2017 15:25
[Define whitespace between two elements] in #pug template syntax. https://github.com/pugjs/pug/issues/905#issuecomment-69221807

Whitespace in Pug (Jade)

pugjs/pug#905 (comment)

Option 1

Note the trailing white-space. Some editors will unfortunately automatically strip this.

input(type='button')
// http://jsbin.com/tuniligupi/edit?js,console
var jsonObj = [
{
"title": "pineapple",
"uid": "ab982d34c98f"
},
{
"title": "carrots",
"uid": "6f12e6ba45ec"