Skip to content

Instantly share code, notes, and snippets.

@thmain
thmain / FluxContextMixin.js
Last active August 29, 2015 14:08
FluxContextMixin using Fluxxor
// Array of constructors for the all registered stores
var registeredStores = [], // List of registered store constructors
registeredStoreNames = [], // StoreNames
registeredActions = {}; // Set of registered actionNames
// Keep the register functions in a closure so that
// there is only one instance of this function irrespective
// of the number of components the mixin is applied to
function registerStore (store) {
var self = this,
//This Program is to find out whether String contains all the unique characters
//With out using any additional data structures
public class UniqueCharString {
private String ip;
public UniqueCharString(String ip) {
this.ip = ip;
}
// method 1 : When characters are not ASCII but could be anything alphabets
public class Print2DArrayInSpiral {
public int arrA[][] = { { 1, 2, 3, 4, 5 }, { 18, 19, 20, 21, 6 },
{ 17, 28, 29, 22, 7 }, { 16, 27, 30, 23, 8 },
{ 15, 26, 25, 24, 9 }, { 14, 13, 12, 11, 10 } };
public int printSpiral(int row_S, int row_E, int col_S, int col_E,
boolean reverse, boolean rowPrint) {
if (row_S > row_E && col_S > col_E) {
public class LongestPrefixSequence {
private String[] arrA;
public LongestPrefixSequence(String[] arrA) {
this.arrA = arrA;
}
public String findPrefix() {
int resultLen = arrA[0].length();
int curr;
public class RotatedArray {
public boolean isRotated(String s1, String s2){
if(s1.length()!=s2.length()){
return false;
}
String sAdd = s1 + s1;
if(sAdd.contains(s2)){
return true;
}else{
return false;
import java.util.Stack;
public class PreOrderTree {
public void preOrderRecursive(Node root) {
if (root != null) {
System.out.print(root.data + " ");
preOrderRecursive(root.left);
preOrderRecursive(root.right);
}
}
package T_InorderIteration;
import java.util.Stack;
public class InorderIretation {
public void inorderRecursive(Node root) {
if (root != null) {
inorderRecursive(root.left);
System.out.print(root.data + " ");
inorderRecursive(root.right);
package T_PostOrder;
import java.util.Stack;
public class PostorderTree {
public void postOrderRecursive(Node root) {
if (root != null) {
postOrderRecursive(root.left);
postOrderRecursive(root.right);
@thmain
thmain / ReactContextTypes.jsx
Last active September 5, 2015 02:14
Passing context types from parent to children in React.
var Grandparent = React.createClass({
childContextTypes: {
foo: React.PropTypes.string.isRequired
},
getChildContext: function() {
return { foo: "I m the grandparent" };
},
import java.util.Comparator;
import java.util.PriorityQueue;
public class MaxRevenueTickets {
PriorityQueue<Integer> pq;
// we will create a max heap
public MaxRevenueTickets(int length) {
pq = new PriorityQueue<>(length, new Comparator<Integer>() {