Skip to content

Instantly share code, notes, and snippets.

View netsi1964's full-sized avatar

Sten Hougaard netsi1964

View GitHub Profile
@netsi1964
netsi1964 / regexp_remove_data_attributes.js
Last active October 24, 2016 08:37
Regexp remove data attributes
reactHTML.replace(/data(.*?)=['"](.*?)['"]/ig,'')
@netsi1964
netsi1964 / addDimensionsToElementsOnPage.js
Created September 30, 2016 12:05
Snippet: add element dimension to its title attribute (tooltip)
Array.from(document.querySelectorAll('*')).map(function(e) {c=getComputedStyle(e);w=c.width;(w!=='auto')?e.setAttribute('title', parseInt(w)+'x'+parseInt(c.height)):'';})
@netsi1964
netsi1964 / README.md
Last active August 23, 2016 12:21
ES2016 namespaces

How I create javascript library using ES2016 and webpack

  • Example Library name: MyLib.js
  • There is one module util

Webpack should have some options set:

output: {
  path: './dist',
 filename: 'MyLib.js',
@netsi1964
netsi1964 / getCode.js
Created August 12, 2016 08:05
Extend Object with method getCode which takes an function and returns the code of the function
Object.prototype.getCode = function() {
var content = this.toString().split("\n");
var last = content.length-1;
var code = content.filter(function(line,i) {
return (i!==0 && i!==last)
})
return code.join("/n")
}
@netsi1964
netsi1964 / README.md
Last active August 9, 2016 06:54
What have I watched on Netflix?

What have I watched on Netflix?

Have you ever wanted a complete list of all the movies you have ever watched on Netflix? This small script should be ran inside the developer console on the (viewing activity)[https://www.netflix.com/viewingactivity] page on netflix. It is in version 0.9 and some things need to be done:

TO-DOs

  • Handle date format
  • Being able to generate more usefull output (like a HTML page)
  • Seems that the count (history) not working... must fix
  • ??
@netsi1964
netsi1964 / toAndFromDataAttribute.js
Created July 24, 2016 20:19
String method to convert to and from a data attribute
String.prototype.toDataProp = function() {
var min = "A".charCodeAt(0),
max = "Z".charCodeAt(0),
res = "data-";
this.split("").forEach(function(char, i) {
var cc = char.charCodeAt(0);
if (cc >= min && cc <= max) {
res += ((i > 0) ? "-" : "") + String.fromCharCode(cc + 32);
} else {
res += char;
@netsi1964
netsi1964 / ipinfo.js
Last active October 30, 2019 08:59
Vanilla javascript XHR request to ipinfo.io
function ipinfo(cb, ip) {
var request;
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
request = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE
try {
request = new ActiveXObject('Msxml2.XMLHTTP');
} catch (e) {
try {
request = new ActiveXObject('Microsoft.XMLHTTP');
@netsi1964
netsi1964 / README.md
Last active July 7, 2016 09:13
IP => Hash

IP to Hash convertion

These two methods can be used to convert IP addresses to and from a hash value.

See the codepen for instructions.

@netsi1964
netsi1964 / svgFromPage.js
Last active July 9, 2016 21:40
SVG from page
var body = document.body,
html = document.documentElement;
var height = Math.max(body.scrollHeight, body.offsetHeight,
html.clientHeight, html.scrollHeight, html.offsetHeight);
var bbox = document.body.getBoundingClientRect();
var svg = '<svg width="' + bbox.width + '" height="' + height + '" viewBox="0 0 ' + bbox.width + ' ' + height + '"><style>rect {-webkit-user-select: none; user-select: none; pointer-events: none; stroke: red; stroke-width: 2px; fill: rgba(0,0,0,.05);}</style>';
Array.prototype.forEach.call(document.querySelectorAll('*:not(.notMe)'), function(ele) {
var style = getComputedStyle(ele);
if (style.display.toLowerCase() !== 'none') {
@netsi1964
netsi1964 / reactJS.js
Created June 14, 2016 10:38
Match ReactJS id
data-reactid="[\.\d:\D]{1,23}"