Skip to content

Instantly share code, notes, and snippets.

View ChathuraGH's full-sized avatar
☺️
coding

Chathura madusanka ChathuraGH

☺️
coding
View GitHub Profile
@ChathuraGH
ChathuraGH / README.md
Created October 17, 2024 06:40 — forked from davelandry/README.md
SVG Text Wrapping

Using d3plus.textwrap, SVG <text> elements can be broken into separate <tspan> lines, as HTML does with <div> elements. In this example, the first column shows normal wrapped text, the second column shows text that is resized to fill the available space, and the third column shows the default SVG behavior.

D3plus automatically detects if there is a <rect> or <circle> element placed directly before the <text> container element in DOM, and uses that element's shape and dimensions to wrap the text. If it can't find one, or that behavior needs to be overridden, they can manually be specified using .shape( ), .width( ), and .height( ).

Featured on D3plus.org

To create anchor links that jump down to different sections of a README (as in an interactive table of contents), first create a heading:
#Real Cool Heading

The anchor link for that heading is the lowercase heading name with dashes where there are spaces. You can always get the anchor name by visiting the README on Github.com and clicking on the anchor that appears when you hover to the left of the heading. Copy everything starting at the #:
#real-cool-heading

Wherever you want to link to your Real Cool Heading section, put your desired text in brackets, followed by the anchor link in parentheses:
[Go to Real Cool Heading section](#real-cool-heading)

@ChathuraGH
ChathuraGH / magiczoomplus-video-gallery.html
Created December 30, 2023 12:03 — forked from Magic-Toolbox/magiczoomplus-video-gallery.html
Magic Zoom Plus gallery combined with YouTube and Vimeo videos
@ChathuraGH
ChathuraGH / Permutate.js
Created December 3, 2023 18:52
Dictionary permutation generator
// console.log([...permutate(['1', '2', '3'], 2)])
// console.log([...permutate(['1', '2', '3'], 3)])
function* permutate(items, count) {
yield* req([])
function* req(array) {
if (array.length == count) {
yield array.join('')
return
@ChathuraGH
ChathuraGH / StringChunker.js
Created December 3, 2023 18:48
String Chunker
function chunkString (str, len) {
const size = Math.ceil(str.length/len)
const r = Array(size)
let offset = 0
for (let i = 0; i < size; i++) {
r[i] = str.substr(offset, len)
offset += len
}
@ChathuraGH
ChathuraGH / load_a_.js
Created December 1, 2023 19:51
To load a .js or .css file dynamically
function loadjscssfile(filename, filetype){
if (filetype=="js"){ //if filename is a external JavaScript file
var fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript")
fileref.setAttribute("src", filename)
}
else if (filetype=="css"){ //if filename is an external CSS file
var fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet")
fileref.setAttribute("type", "text/css")
//Split the string with the spread ... operator instead of .split(''):
'🌯🌯🍣🍻'.split('')
//=> ["\ud83c", "\udf2f", "\ud83c", "\udf2f", "\ud83c", "\udf63", "\ud83c", "\udf7b"]
//vs
[...'🌯🌯🍣🍻']
//=> ["🌯", "🌯", "🍣", "🍻"]
//vs
function Char_Count(str1) {
var chars = {};
str1.replace(/\S/g, function(l){chars[l] = (isNaN(chars[l]) ? 1 : chars[l] + 1);});
return chars;
}
var myString = "This is my String";
console.log(Char_Count(myString));
function countChrOccurence ('hello') {
let charMap = new Map();
const count = 0;
for (const key of str) {
charMap.set(key,count); // initialize every character with 0. this would make charMap to be 'h'=> 0, 'e' => 0, 'l' => 0,
}
for (const key of str) {
let count = charMap.get(key);
charMap.set(key, count + 1);
function countChar(str) {
let myObj= {};
for (let s of str) {
if ( myObj[s] ? myObj[s].count ++ : myObj[s] = { count : 1 } );
}
return myObj;
}
var charCount = countChar('abcceddd');