Skip to content

Instantly share code, notes, and snippets.

View netsi1964's full-sized avatar

Sten Hougaard netsi1964

View GitHub Profile
@netsi1964
netsi1964 / RawHTML.js
Created August 22, 2017 06:30
RawHTML: ReactJS pure component to render HTML
const RawHTML = ({children, className = ""}) =>
<div className={className} dangerouslySetInnerHTML={{ __html: children.replace(/\n/g, '<br />')}} />
@netsi1964
netsi1964 / CopyToClipboard.jsx
Last active March 17, 2025 15:22
ReactJS component: Copy to clipboard
class CopyToClipboard extends React.Component {
copy() {
const textarea = this.textarea;
let { text, onCopy, silent } = this.props;
silent =
typeof silent === "boolean" ||
silent.toLowerCase() == "true" ||
silent == "1";
textarea.value = onCopy.call(this, text);
textarea.select();
@netsi1964
netsi1964 / facebookGroupInfo.js
Created August 6, 2017 10:23
Console snippet: Get Facebook Group information
var sel = "div > div > div > div.clearfix > div._gll > a";
var count = "div._glm > div";
var desc = "div._glo > div";
var groups = Array.from(document.querySelectorAll(sel));
var foundInfo = {};
var json = "";
groups.map(ele => {
var members = ele.parentNode.parentNode.parentNode
.querySelector(count)
.innerText.split(" ")[0];
@netsi1964
netsi1964 / getContentInfo.cs
Created July 31, 2017 14:34
Make HEAD request to get content info as JSON
//Rextester.Program.Main is the entry point for your code. Don't change it.
//Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5
using System;
using System.Net.Http;
namespace Rextester
{
public class Program
@netsi1964
netsi1964 / README.md
Created July 18, 2017 08:15
ES8 aka ES2017 aka EcmaScript 8 aka EcmaScript 2017 released
@netsi1964
netsi1964 / imgToDummyImage.js
Created July 12, 2017 07:00
Replaces any image on page with a Dummyimage.com image showing size
var image = Array.from(document.querySelectorAll('img'));
image.map((ele,i) => {
var {width, height} = getComputedStyle(ele);
var newSrc = `http://dummyimage.com/${parseInt(width)}x${parseInt(height)}`;
if ('src' in ele) {
ele.setAttribute('src', newSrc)
} else {
var url = ele.style.backgroundImage;
console.log(url)
if (url) {
@netsi1964
netsi1964 / SVGPathMinipulation.js
Last active June 14, 2017 07:00
SVG Path manipulation
var path = document.querySelector("path");
function getPathCommands(pathElement) {
var data = pathElement.getAttribute("d");
var ofs = 0;
var indexes = data.match(/[hvmlcqtsaz]/gi).map(function(cmd, i) {
ofs += data.substr(ofs).indexOf(cmd) + 1;
return ofs - 1;
});
var commands = [];
indexes.map(function(curr, i) {
@netsi1964
netsi1964 / lorem.console.js
Created June 5, 2017 08:57
Make site lorem ipsum
var lorem = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quod neque eaque fuga culpa doloribus adipisci vel explicabo! Nihil ipsa commodi quae voluptates laudantium fugit nam. Itaque veniam iure aliquid harum!'
Array.from(document.querySelectorAll("a,h1,h2,h3,h4,h5,h6")).map((ele, i) => {
var img = ele.querySelector('img');
var span = ele.querySelector('span');
if (img) {
var info = getComputedStyle(img);
img.src = 'http://dummyimage.com/'+parseInt(info.width)+'x'+parseInt(info.height)
} else {
if (span) {
span.innerText = lorem.substr(0, span.innerText.length)
@netsi1964
netsi1964 / SKETCH_basicGraphUserPlugin.js
Last active April 29, 2017 11:13
A SKETCH basic graph user plug-in
var sketch = context.api();
var document = sketch.selectedDocument;
var selection = document.selectedLayers;
var page = document.selectedPage;
var values = sketch.getStringFromUser("Enter values", "10,30,10,22,50,10,30");
var canvasWidth = parseFloat(sketch.getStringFromUser("Canvas width", "300"));
var canvasHeight = parseFloat(sketch.getStringFromUser("Canvas height", "300"));
var graphValues = values.split(",");
var min = 1000000, max = -100000, width = canvasWidth / graphValues.length;
@netsi1964
netsi1964 / flowText.js
Last active April 20, 2017 07:53
flowText - a function to add flowing text to SVG
function flowText(text, svg, width, style) {
svg.innerHTML = "";
width = width - style.padding.left;
var svgText = document.createElementNS("http://www.w3.org/2000/svg", "text");
var textNode = document.createTextNode("");
svgText.appendChild(textNode);
var testElement = svg.appendChild(svgText);
var words = text.split(" ");