working on it ...

## Filters

Sort by

Found 133 snippets matching: prettify

### How to prettify a number with thousands or millions

Prepares a pretty version of the given number, with the ability to match the right plural/singular form for English text
public static string PaintNumber(int number, string followingText = "", bool numberInBold = false)
{
string content = String.Format("{0:N0}", number);
if (number >= 10000)
{
double numberInThousands = number / 1000.0;
if (numberInThousands < 100)
content = String.Format("{0:N0}k", numberInThousands);
else
content = String.Format("{0:0.#}M", numberInThousands / 1000.0);
}
if (number >= 1000000)
{
double numberInMillions = number / 1000000.0;
if (numberInMillions < 100)
content = String.Format("{0:N0}M", numberInMillions);
else
content = String.Format("{0:0.#}B", numberInMillions / 1000.0);
}

if (numberInBold)
content = "<b>" + content + "</b>";

if (!string.IsNullOrEmpty(followingText))
content += " " + followingText + (number != 1 ? "s" : "");

return content;
}

### Allows to PrettifyJson

using System;
using System.Text;

public static string Indent = "    ";

public static string PrettifyJson(this string input)
{
try
{
input = input.Replace('\"', '\'');
var output = new StringBuilder(input.Length*2);
char? quote = null;
int depth = 0;

for (int i = 0; i < input.Length; ++i)
{
char ch = input[i];

switch (ch)
{
case '{':
case '[':
output.Append(ch);
if (!quote.HasValue)
{
output.AppendLine();
output.Append(Indent.Repeat(++depth));
}
break;
case '}':
case ']':
if (quote.HasValue)
output.Append(ch);
else
{
output.AppendLine();
output.Append(Indent.Repeat(--depth));
output.Append(ch);
}
break;
case '"':
case '\'':
output.Append(ch);
if (quote.HasValue)
{
if (!output.IsEscaped(i))
quote = null;
}
else quote = ch;
break;
case ',':
output.Append(ch);
if (!quote.HasValue)
{
output.AppendLine();
output.Append(Indent.Repeat(depth));
}
break;
case ':':
if (quote.HasValue) output.Append(ch);
else output.Append(" : ");
break;
default:
if (quote.HasValue || !char.IsWhiteSpace(ch))
output.Append(ch);
break;
}
}

return output.ToString();
}
catch (Exception)
{
return input; // in case we fail to prettify json, handle the exception and just return the input.
}
}

### _ff-addon-snippet-prettifyCssHtmlJs - Shows how to prettify CSS/JS/HTML using the built-in stuff in Firefox.

_ff-addon-snippet-prettifyCssHtmlJs - Shows how to prettify CSS/JS/HTML using the built-in stuff in Firefox.: _ff-addon-snippet-prettifyCssHtmlJs.js
var { devtools } = Components.utils.import("resource://gre/modules/devtools/Loader.jsm", {});
devtools.lazyRequireGetter(this, "beautify", "devtools/jsbeautify");

beautify.css('td{color:red}');
beautify.js('{a:{b:true}}'); // docs on the options, which are passed as second argument: https://dxr.mozilla.org/mozilla-central/source/devtools/shared/jsbeautify/src/beautify-js.js#46

### _ff-addon-snippet-prettifyCss - Shows how to prettify CSS.

_ff-addon-snippet-prettifyCss - Shows how to prettify CSS.: gistfile1.txt
var {CssLogic} = require("devtools/styleinspector/css-logic");
CssLogic.prettifyCSS('td{color:red}')

### Sublime Prettify

Sublime Prettify: .jsbeautifyrc
{
// The plugin looks for a .jsbeautifyrc file in the same directory as the
// source file you're prettifying (or any directory above if it doesn't exist,
// or in your home folder if everything else fails) and uses those options
// along the default ones.

// Details: https://github.com/victorporof/Sublime-HTMLPrettify#using-your-own-jsbeautifyrc-options
// Documentation: https://github.com/einars/js-beautify/
"html": {
"allowed_file_extensions": ["htm", "html", "xhtml", "shtml", "xml", "svg"],
"brace_style": "collapse", // [collapse|expand|end-expand|none]
"end_with_newline": false, // End output with newline
"indent_char": " ", // Indentation character
"indent_handlebars": false, // e.g. {{#foo}}, {{/foo}}
"indent_inner_html": false, // Indent <head> and <body> sections
"indent_scripts": "keep", // [keep|separate|normal]
"indent_size": 2, // Indentation size
"max_preserve_newlines": 10, // Maximum number of line-breaks to be preserved in one chunk
"preserve_newlines": true, // Preserve existing line-breaks
"unformatted": ["a", "span", "img", "code", "pre", "sub", "sup", "em", "strong", "b", "i", "u", "strike", "big","small", "pre", "h1", "h2", "h3", "h4", "h5", "h6"], // List of tags that should not be reformatted
"wrap_line_length": 0 // Maximum characters per line (0 disables)
},
"css": {
"allowed_file_extensions": ["css", "scss", "sass", "less"],
"end_with_newline": false, // End output with newline
"indent_char": " ", // Indentation character
"indent_size": 2, // Indentation size
"selector_separator": " ",
"selector_separator_newline": false // Add a newline between multiple selectors
},
"js": {
"allowed_file_extensions": ["js", "json", "jshintrc", "jsbeautifyrc"],
"brace_style": "collapse", // [collapse|expand|end-expand|none]
"break_chained_methods": false, // Break chained method calls across subsequent lines
"e4x": false, // Pass E4X xml literals through untouched
"end_with_newline": false, // End output with newline
"eval_code": false,
"indent_char": " ", // Indentation character
"indent_level": 0, // Initial indentation level
"indent_size": 2, // Indentation size
"indent_with_tabs": false, // Indent with tabs, overrides `indent_size` and `indent_char`
"jslint_happy": false, // Enable jslint-stricter mode
"keep_array_indentation": false, // Preserve array indentation
"keep_function_indentation": false,
"max_preserve_newlines": 10, // Number of line-breaks to be preserved in one chunk
"preserve_newlines": true, // Preserve line-breaks
"space_after_anon_function": false, // Add a space before an anonymous function's parens, ie. function ()
"space_before_conditional": true,
"space_in_empty_paren": false,
"space_in_paren": false, // Add padding spaces within paren, ie. f( a, b )
"unescape_strings": false, // Decode printable characters encoded in xNN notation
"wrap_line_length": 0 // Wrap lines at next opportunity after N characters
}
}

### Prettify JSON in vim

Prettify JSON in vim: format-json-vim.md
feed this commad to `vim`, bravo!

```
:%!python -m json.tool
```

### JavaScript function to prettify epoch time to human readable and customised date format

JavaScript function to prettify epoch time to human readable and customised date format: pretty_date.js
/*
* Prettifies the epoch time to human redable date format...
* @epoch (Integer) - unix epoch number
* @dateFormat (String) - format in which date should be prettified
*
* @dateForamt string can be composed from following (case sensitive)
* 	DDDD		- Full name of the weekday e.g. Monday
*	DDD		- Short name of the weekday e.g. Mon
*	yyyy 		- Full year e.g. 2015
* 	MMMM		- Full month name e.g. January
* 	MMM		- Short month name e.g. Jan
* 	MM		- Month in two digits
* 	dd		- Date in two digits
* 	hh		- hours
*	mm		- minutes
*	ss		- seconds
*/
function prettyDate(epoch, dateFormat){

//TODO: add args validations here in future..
var shortMonths = 'Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec'.split('_');
var longMonths  = 'January_Febrary_March_April_May_June_July_August_September_Octeber_November_December'.split('_');

var shortDays = 'Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_');
var longDays = 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_');

var _df 	= dateFormat;

// convert epoch date to date object
var 	dt 	= new Date(epoch * 1000);

var	date	= dt.getDate(),
month	= dt.getMonth(),
year	= dt.getFullYear(),
day 	= dt.getDay(),

hour	= dt.getHours(),
mins	= dt.getMinutes(),
secs	= dt.getSeconds();

// year
if (_df && _df.indexOf('yyyy') != -1) {
_df = _df.replace('yyyy', year);
}

// day of week in long format e.g. Monday
if (_df && _df.indexOf('DDDD') != -1) {
_df = _df.replace('DDDD', longDays[day]);
}

// day of week in short format e.g. Mon
if (_df && _df.indexOf('DDD') != -1) {
_df = _df.replace('DDD', shortDays[day]);
}

// date of the month
if (_df && _df.indexOf('dd') != -1) {
_df = _df.replace('dd', date < 10 ? ('0' + date) : date);
}

// Month of the year in long format e.g. January
if (_df && _df.indexOf('MMMM') != -1) {
_df = _df.replace('MMMM', longMonths[month]);
}

// Month of the year in short format e.g. Jan
if (_df && _df.indexOf('MMM') != -1) {
_df = _df.replace('MMM', shortMonths[month]);
}

// Month of the year in numeric format e.g. 01
if (_df && _df.indexOf('MM') != -1) {
_df = _df.replace('MM', (month + 1) < 10 ? ('0' + month) : month);
}

// hours
if (_df && _df.indexOf('hh') != -1) {
_df = _df.replace('hh', hour < 10 ? ('0' + hour) : hour);
}

// minutes
if (_df && _df.indexOf('mm') != -1) {
_df = _df.replace('mm', mins < 10 ? ('0' + mins) : mins);
}

// seconds
if (_df && _df.indexOf('ss') != -1) {
_df = _df.replace('ss', secs < 10 ? ('0' + secs) : secs);
}

return _df;
}

### Prettify dates in emails and autoresponses. Changes "2015-04-13" to "April 13, 2015" or "Apr 13, 2015"

Prettify dates in emails and autoresponses. Changes "2015-04-13" to "April 13, 2015" or "Apr 13, 2015": prettify_dates.html
<?
// Script to create a pretty version of a date field.  Date fields can be
// any field in the supporter record that has type date, time, or datetime.
// You control the data source and the format using these two variables.

// Supporter field name.  Remember to use the API Name for custom fields!
//
var fieldName = "Date_Created";

// Long month if true.  Month abbreviation if false.
//
var longMonth = true;

// The pretty version of the date field will appear in this variable.
//
var prettyDate = null;

// No user-serviceable parts beyond this point.
//
// dates are 'YYYY-MM-DD HH:mm:ss.SSS'
//
var d = Supporter.get(fieldName);
if (d != null) {
var parts = d.split(' ')[0].split('-');
var map = [ "January", "February", "March", "April",
"May", "June", "July", "August", "September",
"October", "November", "December" ];
parts[1] = map[parseInt(parts[1]) - 1];
if (!longMonth) {
parts[1] = parts[1].slice(0, 3);
}
prettyDate = parts[1] + " " + parseInt(parts[2]) + ", " + parts[0];
}
?>

<!-- Example lines to show the difference between using merge fields and SalsaScript fields. You
probably should leave this part out of your page... -->

<p style="text-align: center;"><span style="font-size: x-large;">Supporter Key: [[supporter_KEY]]</span></p>
<p style="text-align: center;"><span style="font-size: x-large;">Date Created: [[Date_Created]]</span></p>
<p style="text-align: center;"><span style="font-size: x-large;">Pretty version: <?= prettyDate ?></span></p>

#### external by Yash Sharma  34  0  1  0

if [ -n "\$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi

if [ "\$color_prompt" = yes ]; then
PS1='\${debian_chroot:+(\$debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\\$ '
else
PS1='\${debian_chroot:+(\$debian_chroot)}\u@\h:\w\\$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "\$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;\${debian_chroot:+(\$debian_chroot)}\u@\h: \w\a\]\$PS1"
;;
*)
;;
esac

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "\$(dircolors -b ~/.dircolors)" || eval "\$(dircolors -b)"
alias ls='ls --color=auto'
#alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'

alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi

# colored GCC warnings and errors
#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'

# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'

# Add an "alert" alias for long running commands.  Use like so:
alias alert='notify-send --urgency=low -i "\$([ \$? = 0 ] && echo terminal || echo error)" "\$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert\$//'\'')"'

# Alias definitions.
# You may want to put all your additions into a separate file like
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi

### Simple Shell Script to Prettify JSON in Text Expander

Simple Shell Script to Prettify JSON in Text Expander: PrettifyJson TextExpander
#!/usr/local/bin/node
console.log(JSON.stringify(%clipboard, null, '\t'));

• Public Snippets
• Channels Snippets