Skip to content

Instantly share code, notes, and snippets.

View rajivnarayana's full-sized avatar

Rajiv Narayana Singaseni rajivnarayana

View GitHub Profile
@rajivnarayana
rajivnarayana / index.html
Created December 20, 2016 12:35
Backbone js Todo list
<div id="new-todo">
<input type="text"><button>Add</button>
</div>
<ul class="todos-list">
</ul>
<script type="text/javascript" src="http://code.jquery.com/jquery-2.1.0.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.7.0/underscore-min.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.2/backbone-min.js"></script>
<script type="text/javascript" src="index.js"></script>
@rajivnarayana
rajivnarayana / nginx.conf
Created October 31, 2016 21:01
Deploy multiple server instances and use nginx to configure which paths to hit.
http{
...
...
server {
listen 80;
server_name example.com;
location /admin {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
@rajivnarayana
rajivnarayana / polynomialRegression.py
Created October 24, 2016 16:11
Polynomial Regression using scipy
import csv
datafile = open('home_data.csv', 'r')
datareader = csv.reader(datafile,delimiter=',')
data = []
for row in datareader:
data.append(row)
print data[0]
print data[0][5]
print data[0][3]
@rajivnarayana
rajivnarayana / primes.js
Last active August 31, 2016 08:01
Find all primes till certain limit.
var primesUsingEratosthenesMethod = function(num) {
return new Array(num).fill(1).map((key, index) => index + 1).reduce((primesLessThanCur, cur) => {
if (cur < 2) return primesLessThanCur;
if (primesLessThanCur.filter(prime => prime * prime <= cur).every(prime => cur % prime != 0)) {
return primesLessThanCur.concat(cur);
}
return primesLessThanCur;
}, [])
}
@rajivnarayana
rajivnarayana / assignment.js
Created August 4, 2016 14:49
Array manipulations in Javascript
let list = [9,5,5,0,2,5,9,5,6,7];
//find if any of the number is greater than 6
//find the sum of all numbers
//find the number of even numbers and number of odd numbers
//find how many times each number repeats
//find an array where each number is the squares the corresponding number in the first array.
//find an array where the character representing the number repeats the number of times of the corresponding number
// ex : [2, 3, 1] = ['c','c','d','d','d','b']
var result = list.some(function(element) {
return element > 10;
@rajivnarayana
rajivnarayana / README.MD
Created May 26, 2016 14:24
Facebook connect web flow.

Create a folder fbconnect (or whatever you like) Save contents of above file as index.js Replace APP_ID and APP_SECRET in lines 4 and 5 with your application specific constants. npm install --save express node index.js Will start the server.

Open a browser and go to http://localhost:3001/fbconnect

@rajivnarayana
rajivnarayana / MultiplePromises.js
Created February 29, 2016 12:35
Callbacks vs promises
var driverDetailsPromise = Driver.findWithPromises({_id:req.params.id}).then(function(drivers){
return drivers[0];
})
var tripsByDriverPromise = Request.findWithPromises({driver_id:req.params.id});
Promise.all([driverDetailsPromise, tripsByDriverPromise]).then(function(results){
var firstDriverDetails = results[0];
var tripsByDriver = results[1];
response.status(200).send({'details': firstDriverDetails, 'trips' : tripsByDriver});
@rajivnarayana
rajivnarayana / frame_layout_demo.xml
Created December 15, 2015 04:46
Sample xml for Frame layout
<Page xmlns="http://schemas.nativescript.org/tns.xsd" loaded="pageLoaded" xmlns:frame="modules/frame-layout">
<frame:FrameLayout>
<Image src="res://Default" stretch="aspectFill"/>
<DockLayout stretchLastChild="false" gravity="bottom" style="padding: 10; color:white; margin: 10; background-color: #aa000000">
<Label text="Bottom Left" dock="left" />
<Label text="Bottom Right" dock="right" />
</DockLayout>
</frame:FrameLayout>
</Page>
import { EventData, Observable } from "data/observable";
import { Page } from "ui/page";
var dateConverter = {
toView: function (value, format) {
var result = format;
var day = value.getDate();
result = result.replace("DD", day < 10 ? "0" + day : day);
var month = value.getMonth() + 1;
result = result.replace("MM", month < 10 ? "0" + month : month);
@rajivnarayana
rajivnarayana / Collapsible_Responsive_Tabs.html
Created May 7, 2015 12:31
A no javascript responsive layout that shows tabs for smaller screen widths. Uses radio buttons to switch tabs.
<style>
ul.tabs > li::before {
content : '';
}
@media (max-width: 600px) {
ul.tabs input[type=radio] {
position: absolute;
top: -9999px;