Skip to content

Instantly share code, notes, and snippets.

@JamoCA
Created January 17, 2023 00:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JamoCA/ce221b2cec8da53e62542dd2b4f22a5b to your computer and use it in GitHub Desktop.
Save JamoCA/ce221b2cec8da53e62542dd2b4f22a5b to your computer and use it in GitHub Desktop.
CFML version of reddit r/ProgrammerHumor code
<cfscript>
/* 2023-01-16 https://twitter.com/PR0GRAMMERHUM0R/status/1615061348928339968 https://www.reddit.com/r/programmerhumor/comments/10dh6x1
/* It's real code: https://github.com/MinBZK/woo-besluit-broncode-digid-app/blob/ad2737c4a039d5ca76633b81e9d4f3f9370549e4/Source/DigiD.iOS/Services/NFCService.cs#L182 *
/* Updated to accept either decimal or integer values. Try it at https://www.trycf.com/ */
string function progressBar(required numeric percentage=0, fill="&##9608;", empty="&##9618;"){
if (arguments.percentage lt 0 || arguments.percentage gt 100){
local.p = 0;
} else if ( arguments.percentage gt 1 && arguments.percentage lt 100){
local.p = int(arguments.percentage / 10);
} else {
local.p = int(arguments.percentage * 10);
}
local.b = '<span title="#arguments.percentage#%">' & repeatstring(arguments.fill, local.p) & repeatstring(arguments.empty, 10-local.p) & '</span>';
return local.b;
}
tests = [0, 0.05, 0.20, 0.45, 0.67, 1, 85, 90];
for(test in tests){
writeoutput("<br><tt>#numberformat(test,'009.99')#</tt> = #progressbar(test)#");
}
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment