Skip to content

Instantly share code, notes, and snippets.

Avatar

JDMCreator JDMCreator

View GitHub Profile
@JDMCreator
JDMCreator / CSVtoArray.js
Created Jul 31, 2017
Import CSV (from a String) as an Array (double-quotes support)
View CSVtoArray.js
/*
Syntax : Array importCSV(String text)
example : importCSV('ab,cd,ed\n"ab","cd","ef"')
*/
function importCSV(text){
text = text.replace(/^[\n\r]+/, "").replace(/[\n\r]+$/, "") + "\n";
var table = [],
row = [],
indbl = false,
start = true,
@JDMCreator
JDMCreator / toASCII.js
Created Jun 4, 2017
Convert a String to ASCII (Convert accented characters to normal characters and remove others characters)
View toASCII.js
function toASCII(str){
var newstr = "",
graph_table = {
"\u0132" : "IJ",
"\u0152" : "OE",
"\u00C6" : "AE",
"\u00D8" : "O"
}
str = str.normalize("NFD");
for(var i=0, code, char;i<str.length;i++){
@JDMCreator
JDMCreator / long.js
Last active May 18, 2017
HSL to RGB // IE9+ // 174 bytes
View long.js
/*
Returns a [R,G,B] array. [R,G,B] are [0,255] numbers. [h,s,l] are [0,1] numbers
*/
function(h, s, l){
s=l < 0.5 ? l * (1 + s) : l + s - l * s,
l = 2 * l - s;
return [h+1/3,h,h-1/3].map(function(t,c){
return (((c=s-l,t+=t<0?1:t>1?-1:0)<1/6?l+6*c*t:.5>t?s:t<2/3?l+c*(2/3-t)*6:l)*255)+.5|0;
});
}
@JDMCreator
JDMCreator / annotated.js
Last active May 18, 2017
Convert HEX to RGBA (supports RGB, RRGGBB, RGBA and RRGGBBAA with or without hashtag symbol) // 111 bytes
View annotated.js
/*
Returns a [R,G,B,A] array. [R,G,B] are [0,255] numbers and A is a [0,1] number
*/
function(a){
return [
( v=255, // We set a variable inside the array to save "var"
c = "0x"+ // Convert from hexadecimal to decimal
/\w{8}/.exec( // We take the first eight alphanumerical characters
a.replace( // We convert short hexadecimal to long hexadecimal (RGB(A)->RRGGBB(AA))
!a[6] && /./g, // We only convert if it's a short hexadecimal
@JDMCreator
JDMCreator / getMatrixOfCells.js
Created May 16, 2017
Fixed javascript "Table.rows" (including rowSpan and colSpan)
View getMatrixOfCells.js
/****
This function create a matrix of cells from a table. It take care of merged cells (cells with "rowspan>1" or "colspan>1" attributes).
====| Syntax |====
@Array getMatrixOfCells(@TableElement table, [Optional @Boolean alwaysInterpretZeroRowSpan])
table : A <TABLE> HTML Element
alwaysInterpretZeroRowSpan : Optional (default : false). If set to true, "rowspan=0" attributes are always interpreted as if it was implemented in the browser (even if it's not)
You can’t perform that action at this time.