Skip to content

Instantly share code, notes, and snippets.

View bharathvaj-ganesan's full-sized avatar
🏠
Working from home

Bharathvaj bharathvaj-ganesan

🏠
Working from home
View GitHub Profile
@bharathvaj-ganesan
bharathvaj-ganesan / polling.js
Created July 29, 2018 10:23
Long Polling client
/* Client - subscribing to the github events */
subscribe: (callback) => {
const pollUserEvents = () => {
$.ajax({
method: 'GET',
url: 'http://localhost:8080/githubEvents',
success: (data) => {
callback(data) // process the data
},
complete: () => {
@bharathvaj-ganesan
bharathvaj-ganesan / nginx.conf
Created May 2, 2018 01:47 — forked from turtlesoupy/nginx.conf
node.js upstream nginx config
http {
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=one:8m max_size=3000m inactive=600m;
proxy_temp_path /var/tmp;
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
gzip_comp_level 6;
<section style={{ padding: 4em; background: papayawhip; }}>
<h1 style={{ font-size: 1.5em; text-align: center; color: palevioletred; }}> Hello World, this is my first styled component!</h1>
</section>
import React from 'react';
import styled from 'styled-components';
// Create a <Title> react component that renders an <h1> which is
// centered, palevioletred and sized at 1.5em
const Title = styled.h1`
font-size: 1.5em;
text-align: center;
color: palevioletred;
<script src="https://cdnjs.cloudflare.com/ajax/libs/dompurify/0.8.2/purify.min.js"></script>
<script>
function sanitize(strings, ...values) {
const dirty = strings.reduce((prev, next, i) => `${prev}${next}${values[i] || ''}`, '');
console.log(dirty);
console.log(aboutMe);
return DOMPurify.sanitize(aboutMe);
}
const name = 'petyr baelish';
function highlight(strings, ...values) {
// here i is the iterator for the strings array
return strings.reduce((result, string, i) => {
return `${result}${string} <cite>${values[i] || ''}</cite>`;
}, '');
}
const author = 'Thomas A. Edison';
const statement = `I have not failed. I've just found 10,000 ways that won't work.`;
const quote = highlight`${statement} by ${author}`;
@bharathvaj-ganesan
bharathvaj-ganesan / README.md
Created January 1, 2018 11:34 — forked from mapsam/README.md
Namecheap > Github pages

Namecheap > Github pages

Pointing your domains to a gh-pages branch requires three steps.

  1. Add the Github IPs as A records on Namecheap. Both Github IPs are 192.30.252.153 and 192.30.252.154.
  2. Add your Github domain as the CNAME alias on Namecheap. your_username.github.io. (mind the extra period!)
  3. Add a CNAME with your new domain name in your repository. lowercase and nothing else
Let's lool at the following example structure for RESTful API using Node.js, Express.js included tesing
app/
|---models/
|---controller/
|---helpers/
|---middlewares/
|---tests/
|---models/
|---controllers/
@bharathvaj-ganesan
bharathvaj-ganesan / random.md
Created October 9, 2017 12:38 — forked from joepie91/random.md
Secure random values (in Node.js)

Not all random values are created equal - for security-related code, you need a specific kind of random value.

A summary of this article, if you don't want to read the entire thing:

  • Don't use Math.random(). There are extremely few cases where Math.random() is the right answer. Don't use it, unless you've read this entire article, and determined that it's necessary for your case.
  • Don't use crypto.getRandomBytes directly. While it's a CSPRNG, it's easy to bias the result when 'transforming' it, such that the output becomes more predictable.
  • If you want to generate random tokens or API keys: Use uuid, specifically the uuid.v4() method. Avoid node-uuid - it's not the same package, and doesn't produce reliably secure random values.
  • If you want to generate random numbers in a range: Use random-number-csprng.

You should seriously consider reading the entire article, though - it's

var users = [
{id: 1, name: "John", email: "[email protected]"},
{id: 2, name: "Mary", email: "[email protected]"},
{id: 3, name: "Bob", email: "[email protected]"}
];
//helper func
var viewModelMap = function(signature) {
var map = {}
return function(key) {
if (!map[key]) {