Skip to content

Instantly share code, notes, and snippets.

View vinaypuppal's full-sized avatar
🤓
Working from home

vínαч puppαl vinaypuppal

🤓
Working from home
View GitHub Profile
/* Made by ciara.io for Meteor Academy */
body {
color: #333;
font-family: sans-serif;
font-size: 115%;
line-height: 24px;
}
footer {

Source from this course: https://udacity.com/course/intro-to-ajax--ud110

What is CORS and why are we using it?

CORS works around a sometimes overly-strict browser policy(i.e same-origin policy) meant to protect servers from malicious requests. CORS is enabled on the server-side, so you won't generally need to worry about it for your code. You do need to know about it though, since some APIs support it, and some do not.

The same-origin policy was implemented by web browsers to prevent malicious scripts from untrusted domains from running on a website. In other words, it ensures sure that scripts from one website can't insert themselves into another.

For example, the same-origin policy keeps the bad guys’ JavaScript from somehow running on your bank’s website and stealing your information.

Over time, developers realized that this policy was too strict, and often got in the way of legitimate use-cases. There are many reasons to serve content from multiple domain origins, and so developers found a way

@vinaypuppal
vinaypuppal / now-realias.js
Created September 6, 2016 11:38 — forked from remy/now-realias.js
Quick `now` re-alias script, if run inside the current project dir
#!/usr/bin/env node
const Now = require('now-client');
const now = Now(); // this looks like it detect the token from ~/.now.json or the env automatically
const pkg = require(process.cwd() + '/package.json');
now.getDeployments().then(res => {
const [latest, prev, ...rest] = res.filter(_ => _.name === pkg.name).sort((a, b) => b.created - a.created);
console.log(`getting alias for ${prev.uid} (${prev.url})`);
return now.getAliases(prev.uid).then(res => {
@vinaypuppal
vinaypuppal / JSON_to_URLEncoded.js
Created September 30, 2016 21:20 — forked from lastguest/JSON_to_URLEncoded.js
Convert JavaScript object to x-www-form-urlencoded format
function JSON_to_URLEncoded(element,key,list){
var list = list || [];
if(typeof(element)=='object'){
for (var idx in element)
JSON_to_URLEncoded(element[idx],key?key+'['+idx+']':idx,list);
} else {
list.push(key+'='+encodeURIComponent(element));
}
return list.join('&');
}

Keybase proof

I hereby claim:

  • I am vinaypuppal on github.
  • I am vinaypuppal (https://keybase.io/vinaypuppal) on keybase.
  • I have a public key whose fingerprint is 555A D17F 3449 6347 B255 599F 40B2 391F C2D9 8337

To claim this, I am signing this object:

@vinaypuppal
vinaypuppal / LinkSmoothScroll.js
Last active March 17, 2022 19:10
Next.js smooth scroll
import React, { Children } from 'react'
import Router from 'next/router'
import smoothScroll from '../utils/smoothScroll'
// this HOC is taken from https://github.com/zeit/next.js/blob/master/lib/link.js and modified
export default class LinkSmoothScroll extends React.Component {
constructor (props) {
super(props)
this.linkClicked = this.linkClicked.bind(this)
}
@vinaypuppal
vinaypuppal / fonts.css
Created August 2, 2017 10:48
UI System fonts in web
body {
font-family:
/* 1 */ -apple-system, BlinkMacSystemFont,
/* 2 */ "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans",
/* 3 */ "Helvetica Neue", sans-serif;
}
@vinaypuppal
vinaypuppal / readme.md
Last active November 22, 2017 07:07
GITHUB_OAUTH
  • On Frontend
    • User clicks Login With Github Button.
    • We redirect user to https://github.com/login/oauth/authorize with client_id, redirect_uri and scope as query params.
    • Example
      https://github.com/login/oauth/authorize?scope=user:email&client_id=<CLIENT_ID>&state=<state>
      
    • Once user allows access github redirect back us to supplied redirect_uri with code as query parameter.
    • Example
@vinaypuppal
vinaypuppal / index.html
Created August 20, 2018 04:28
Electron Fiddle Gist
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
</head>
<body>
<h1>Hello World!</h1>
<!-- All of the Node.js APIs are available in this renderer process. -->
We are using Node.js <script>document.write(process.versions.node)</script>,
@vinaypuppal
vinaypuppal / index.html
Created August 20, 2018 04:45
Electron Fiddle Gist
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
</head>
<body>
<h1>Hello World!</h1>
<!-- All of the Node.js APIs are available in this renderer process. -->
We are using Node.js <script>document.write(process.versions.node)</script>,