Skip to content

Instantly share code, notes, and snippets.

View chetanraj's full-sized avatar
🎯
Focusing

Chetan chetanraj

🎯
Focusing
View GitHub Profile
@chetanraj
chetanraj / percentage.js
Created May 25, 2016 11:58
Percentage Calculation - Rounding off to Single Decimal Point
// Require Underscore.js
Percentage = function(numbers) {
var percentage = [],
sum = _.reduce(numbers, function(m, number){ return m + number; }, 0);
for(var n = 0; n < numbers.length; n++){
percentage[n] = parseFloat((numbers[n]/sum * 100).toFixed(3));
percentage[n] = Math.round(percentage[n] * 10)/10;
};
# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to log to the console when each text editor is saved.
#
# atom.workspace.observeTextEditors (editor) ->
# editor.onDidSave ->
{
"extends": [
"eslint:recommended",
"plugin:react/recommended"
],
"parser": "babel-eslint",
"env": {
"browser": true,
"jest": true
},
@chetanraj
chetanraj / .prettierrc
Created May 4, 2019 03:44
My Prettier config
{
"bracketSpacing": true,
"jsxBracketSameLine": true,
"singleQuote": true,
"semi": true,
"trailingComma": "none",
"tabWidth": 2
}
@chetanraj
chetanraj / .stylelintrc
Created May 6, 2019 08:08
My stylelint config
{
"rules": {
"color-hex-case": "lower",
"block-no-empty": true,
"number-leading-zero": "never",
"declaration-colon-space-after": "always",
"declaration-colon-space-before": "never",
"color-hex-length": "short",
"indentation": 2,
"string-quotes": "double",
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1" name="viewport">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css" rel="stylesheet"
type="text/css" />
<link href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
const response = {
"data": {
"query": "What is javascript ?",
"answer" : {
"value": "JavaScript is 💛"
}
}
}
let theValue;
if(response &&
response.data &&
response.data.answer &&
response.data.answer.value) {
theValue = response.data.answer.value;
} else {
theValue = 'JavaScript is BAE 💛❤️';
}