Skip to content

Instantly share code, notes, and snippets.

View VFDan's full-sized avatar
🏳️‍🌈
Pride is year-round

Luvexina VFDan

🏳️‍🌈
Pride is year-round
  • 23:15 (UTC -04:00)
View GitHub Profile
@VFDan
VFDan / wikipedia_watchlist_link.js
Last active October 2, 2020 18:37
Makes the link in the Wikipedia dropdown watchlist link to the edit watchlist page
@VFDan
VFDan / math.js
Created March 24, 2020 17:19
Median and mean
Math.median = (...nums) => {
nums.sort()
len = nums.length/2
if (len%1) return nums[Math.floor(len)]
return mean(nums[len],nums[len-1])
}
Math.mode = (...nums) => nums.reduce((a,b)=>a+b, 0)/nums.length
@VFDan
VFDan / js.js
Last active March 11, 2020 19:45
JavaScript code that outputs “JavaScript!”, in the shape of “JS”
x=(__)=>'J'+ 'ava'+///
'S'+ //
'c'+ 'ript!'//
/**/ /**/ //
console.log( x(1))////
@VFDan
VFDan / CSS.js
Created July 21, 2019 00:04
Add CSS styles with JS
function addCSS(a,b,c){b.match(/-/)&&(b=b.replace(/-([a-z])/g,function(a){return a[1].toUpperCase()}));for(var d=document.querySelectorAll(a),e=d.length,f=0;f<e;f++)d[f].style[b]=c}function addCSSRules(a){var b,c=document.createElement("style");document.head.appendChild(c),b=c.sheet;for(var d=0,e=a.length;d<e;d++){var f=1,g=a[d],h=a[d][0],k="";"[object Array]"===Object.prototype.toString.call(g[1][0])&&(g=g[1],f=0);for(var l,m=g.length;f<m;f++)l=g[f],k+=l[0]+":"+l[1]+(l[2]?" !important":"")+";\n";b.insertRule(h+"{"+k+"}",b.cssRules.length)}}!function(a){var b=a.insertRule;2===b.length&&(a.insertRule=function(c){t:for(var d=0,f=c.length,g=0,h=0;d!==f;++d){if(h=c.charCodeAt(d),!g&&123===h){for(var j=d,a=-1;d!==f;++d)h=c.charCodeAt(d),g||125!==h||(a=d),g^=92===h?1:g;if(-1==a)break t;return b.call(this,c.substring(0,j),c.substring(a),arguments[3])}g^=92===h?1:g}return b.call(this,c,"",arguments[2])})}(CSSStyleSheet.prototype);
/* How to use:
* addCSS(selector, property, value)
* * addCSS('div:first-of-type', 'c
@VFDan
VFDan / rand-num.js
Created April 7, 2019 20:09
Random Number Generator (JS)
function randomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
@VFDan
VFDan / emphasis-if.less
Last active April 7, 2019 20:52
A LESS function to add emphasis, and also an if operator.
.if(@condition, @property, @value) when (@condition = true){
@{property}: @value;
}
.emphasis(@bold: false, @italic: false, @underline: false, @overline: false){
.if(@bold, font-weight, bold);
.if(@italic, font-style, italic);
.if(@underline, text-decoration, underline);
.if(@overline, text-decoration, overline);
}