Skip to content

Instantly share code, notes, and snippets.

View rajivnarayana's full-sized avatar

Rajiv Narayana Singaseni rajivnarayana

View GitHub Profile
@rajivnarayana
rajivnarayana / ColorTransformingPagerExample.java
Created November 20, 2014 20:32
An android activity that sets up a view page that changes background color as you scroll. As seen in https://play.google.com/store/apps/details?id=ch.bitspin.timely
public class MainActivity extends ActionBarActivity {
private ViewPager mViewPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final int[] mColors = new int[3];
mColors[0] = Color.BLUE;
@rajivnarayana
rajivnarayana / GeoLocationPlugin-cordova.3x.js
Created March 18, 2015 13:35
The java script for Cordova geolocation plugin 'org.apache.cordova.geolocation' to be used when you had to serve cordova.3x.js from remote server.
cordova.define("org.apache.cordova.geolocation.Coordinates", function(require, exports, module) { /*
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
@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;
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 / 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>
@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 / 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 / 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 / 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 / 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]