This was my response to a stackoverflow question: http://stackoverflow.com/questions/36045974/how-to-create-an-editable-textbox/36046548#36046548
Wednesday, March 16, 2016
Edit textbox on clicking an image & save on clicking outside
Monday, March 7, 2016
React ContentEditable Div
A custom contentEditable div, with placeholder text styling:
Part 1: The JSX component file
var ContentEditableDiv = module.exports = React.createClass({
handleKeyPress: function(e){
e.stopPropagation();
if(getKeyCode(e) == 13) {
e.preventDefault();
e.target.blur();
if(this.props.onEnterKey) this.props.onEnterKey(e);
}
},
onBlur: function(e){
e.stopPropagation();
// console.log('blurring called from content_editable div react');
if(this.props.onBlur) {
console.log('e', e);
var el = $(e.target);
var text = $.trim(el.text());
el.text(text); //just to keep it in sync
this.props.onBlur(text, e);
}
},
onKeyDown: function(e){
if(this.props.onKeyDown) this.props.onKeyDown(e);
},
render: function(){
// console.log('render content content_editable', this.props.text.length);
var klass = this.props.class + " content_editable";
var placeholder = this.props.placeholder ? this.props.placeholder : "Type here";
return (
<div classname="{klass}" contenteditable="{true}" id="{this.props.id}" onblur="{this.onBlur}" onkeydown="{this.props.onKeyDown}" onkeypress="{this.handleKeyPress}" placeholder="{placeholder}">
{this.props.text}
</div>
)
}
});
Part 2: CSS Styling:
.content_editable
border: none
outline: none
height: 17.55px
padding-right: 2px !important
&:focus
white-space: normal
border-bottom: 1px solid black
.content_editable:empty:before
content: attr(placeholder)
display: block /* For Firefox */
&:hover
cursor: text
.content_editable:focus:empty:before
content: ""
display: block /* For Firefox */
margin-top: 19px /* To make sure the border doesn't go up */
min-width: 90px
Jquery list attributes of an element
$('#ElemId').each(function() {
$.each(this.attributes, function() {
// this.attributes is not a plain object, but an array
// of attribute nodes, which contain both the name and value
if(this.specified) {
console.log(this.name, this.value);
}
});
});
SVG Add Class, Delete Class for Jquery
svgAddClass($(".myClass"), "selected_class");
svgRemoveClass($(".myClass"), "selected_class");
/**
date: 26th Jan 2016
Jquery doesn't support add class for svg currently
workaround function for that
**/
function svgAddClass(svgElem, className){
var classList = svgElem.attr('class') + " " +className;
console.log('classList', classList);
svgElem.attr('class', classList);
}
function svgRemoveClass(svgElem, className){
var classList = svgElem.attr('class').replace(className, '');
console.log('classList', classList);
svgElem.attr('class', classList);
}
Tuesday, November 24, 2015
Steps to get license for Desktop Alarm Clock
To get a license key for the Desktop Alarm Clock,
1. Email dhiviyadhanasekar@gmail.com, requesting for author's bank account details. Email subject should be "Desktop Alarm Clock - License Request".
2. Once you receive an email with bank account details, transfer the amount specified in the email to the bank account and email back with the transaction reference.
3. Once the transaction has completed, author will email you back the the user name and license key.
Note: The above was done to hack the payment link on an application that I reverse engineered and by pass the registration process by reverse engineering the application using OllyDbg and creating a patch, that would exploit the application's security\vulnerabilities.
1. Email dhiviyadhanasekar@gmail.com, requesting for author's bank account details. Email subject should be "Desktop Alarm Clock - License Request".
2. Once you receive an email with bank account details, transfer the amount specified in the email to the bank account and email back with the transaction reference.
3. Once the transaction has completed, author will email you back the the user name and license key.
Note: The above was done to hack the payment link on an application that I reverse engineered and by pass the registration process by reverse engineering the application using OllyDbg and creating a patch, that would exploit the application's security\vulnerabilities.
Friday, September 18, 2015
Subtree Sum
Problem
Find subtrees with nodes that add to a given sumExample Input:
Sum = 5Tree is:
1
/ \
2 3
/ \ / \
2 -1 0 8
/\ /\ /\ /\
0 3 -5 4 6 -9 -6 1
Output:
2
0 3
null null null null
--------------------
2
2 -1
0 3 -5 4
null null null null null null null null
--------------------
Solution
package Tree;
import java.util.ArrayList;
public class SubtreeSum {
private ArrayList sumPaths;
private Integer traverse(Tree t, int sum){
if(t == null) return 0;
Integer leftSum = traverse(t.left, sum);
Integer rightSum = traverse(t.right, sum);
// if(leftSum == null || rightSum == null) return null;
Integer curSum = leftSum + rightSum + t.val;
// if(curSum > sum) return null;
if(curSum == sum) { sumPaths.add(t);}
return curSum;
}
public void printSubTreeWithSum(Tree t, int sum){
sumPaths = new ArrayList();
traverse(t, sum);
for(int i = 0; i < sumPaths.size(); i++){
TreeOperations.printTree(sumPaths.get(i));
System.out.println("--------------------");
}
}
public static void main(String[] args) {
SubtreeSum ob = new SubtreeSum();
Tree t = TreeTestData.getSampleTree3();
ob.printSubTreeWithSum(t, 5);
}
}
Tree - Sum Paths
Problem
Given a binary tree, not necessarily a BST return all paths with sum x:Example for sum =5 and tree given below:
1
/ \
2 3
/ \ / \
2 -1 0 8
/\ /\ /\ /\
0 3 -5 4 6 -9 -6 1
Output is: [[1,2,2],[2,3],[1,2,2,0],[2,-1,4],[3,8,-6]]
Solution
public class Tree{
int val;
Tree left;
Tree right;
}
package Tree;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
public class TreeSumPath {
Set< ArrayList<Integer> > sumPaths2;
void doTraversal(Tree t, int remain, int oSum, ArrayList temp){
temp.add(t.val);
if(remain == 0) sumPaths2.add(temp);
traverse2(t.left, remain, temp, oSum);
traverse2(t.right, remain, temp, oSum);
}
void traverse2(Tree t, int sum, ArrayList curNodes, int oSum){
if(t==null) return;
ArrayList temp = new ArrayList(curNodes);
doTraversal(t, sum - t.val, oSum, temp);
temp = new ArrayList();
doTraversal(t, oSum-t.val, oSum, temp);
}
Set< ArrayList<Integer> > getSumPaths(Tree t, int sum){
sumPaths2 = new HashSet< ArrayList>();
traverse2(t, sum, new ArrayList(), sum);
System.out.println(sumPaths2);
return sumPaths2;
}
public static void main(String[] args) {
Tree t = TreeTestData.getSampleTree3();
TreeSumPath ob = new TreeSumPath();
ob.getSumPaths(t, 5);
}
}
Subscribe to:
Posts (Atom)