Skip to content

Instantly share code, notes, and snippets.

@thmain
thmain / MyReactComponent.js
Last active October 15, 2022 18:58
Skeleton React Component with descriptions for all of its lifecycle methods
/**
* @jsx React.DOM
*/
var React = require('react'),
MyReactComponent = React.createClass({
// The object returned by this method sets the initial value of this.state
getInitialState: function(){
return {};
@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,
@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" };
},
public class QuickSort {
private int[] arrA;
public QuickSort(int[] arrA) {
this.arrA = arrA;
}
public void quickS(int low, int high) {
int mid = (low + high) / 2;
int left = low;
//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
import java.util.*;
public class TwoNumbersInArray {
private int[] arrA;
private int number;
public TwoNumbersInArray(int[] arrA, int number) {
this.arrA = arrA;
this.number = number;
}
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 ReplaceAllSpaces {
public void replace(String s1, int length) {
char[] chars = s1.toCharArray();
int spaceCount = 0;
for (int i = 0; i < length; i++) {
if (chars[i] == ' ') {
spaceCount++;
}
}
public class StringCompression {
public String compression(String s1){
StringBuffer sb = new StringBuffer();
int count =1;
char prev = s1.charAt(0);
for(int i=1;i<s1.length();i++){
char curr =s1.charAt(i);
if(prev==curr){