Skip to content

Instantly share code, notes, and snippets.

View alenthomas's full-sized avatar
🏠
Working from home

Alen Thomas alenthomas

🏠
Working from home
View GitHub Profile
@alenthomas
alenthomas / pyramid.py
Last active November 16, 2016 13:26
Print pyramid python
def pyramid(num):
for i in range(1, num+1):
if i == num:
for j in reversed(range(1, num+1)):
print('*'*j)
else:
print('*'*i)
[
{
"firstname": "Alen",
"lastname": "Thomas"
},
{
"firstname": "Alen",
"lastname": "Thomas"
},{
"firstname": "Alen",
{"Category":
[{"category":"auto-driver","display":"Vehicle No"},
{"category":"shopkeeper", "display":"Shop Name"},
{"category":"medical", "display": "Medical Store Name"}]
}
}
@alenthomas
alenthomas / tic-tac-toe.js
Last active September 19, 2017 20:31
A function which takes an array(ary) and an array of indexes(< ary.length) and sets 'X' for the for ary[indexes] else sets 'O'
// in js using for-loop
function swap(ary, indexes) {
var visited = [];
var newAry = Array(ary.length).fill(null);
for(let i=0; i<indexes.length; i++) {
newAry[indexes[i]] = 'X';
visited.push(indexes[i]);
}
for(let i=0; i<newAry.length; i++) {
if(newAry[i] === null) {
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<div id="demo"></div>
<button onclick="start();">Start</button>
// src/OktaAuthComponent.js
import React, { Component } from 'react';
import { Redirect } from 'react-router-dom';
import { withAuth } from '@okta/okta-react';
export const OktaAuthComponent = withAuth(class Auth extends Component {
constructor(props) {
super(props);
this.state = { authenticated: null };
this.checkAuthentication = this.checkAuthentication.bind(this);
this.checkAuthentication();
@alenthomas
alenthomas / App.js
Last active September 17, 2018 18:27
import React, { Component } from 'react';
import { BrowserRouter, Route } from 'react-router-dom';
import { Security, ImplicitCallback } from '@okta/okta-react';
import { OktaAuthComponent, OktaLogout } from './OktaAuthComponent.js'
const config = {
issuer: 'https://*****.oktapreview.com/oauth2/default', // replace this with your okta dev url
redirect_uri: window.location.origin + '/implicit/callback',
client_id: '****' // replace this with your okta client_id
}
// src/OktaAuthComponent.js
import React, { Component } from 'react';
import { Redirect } from 'react-router-dom';
import { withAuth } from '@okta/okta-react';
export const OktaAuthComponent = withAuth(class Auth extends Component {
constructor(props) {
super(props);
this.state = { authenticated: null };
this.checkAuthentication = this.checkAuthentication.bind(this);
this.checkAuthentication();
import React, { Component } from 'react';
import { BrowserRouter, Route } from 'react-router-dom';
import { Security, ImplicitCallback } from '@okta/okta-react';
import { OktaAuthComponent, OktaLogout } from './OktaAuthComponent.js'
const config = {
issuer: 'https://*****.oktapreview.com/oauth2/default', // replace this with your okta dev url
redirect_uri: window.location.origin + '/implicit/callback',
client_id: '****' // replace this with your okta client_id
}
@alenthomas
alenthomas / array-reduce.js
Created March 29, 2019 04:03
1d-array to 2d-array with reduce
let postObject = posts.reverse().reduce((acc, ele) => {
if(acc.s > 0) {
return {arr: [ele, ...acc.arr], rows: acc.rows, s: acc.s-1}
} else {
return {arr: [ele], rows: [acc.arr, ...acc.rows], s: 2};
}
}, {arr: [], rows: [], s: 3});
let rows = [[...postObject.arr], ...postObject.rows ];