Skip to content

Instantly share code, notes, and snippets.

@bansalayush
bansalayush / CloneTest.java
Created February 28, 2017 05:58
Cloning example and concept
/*
* Cloning creates an exact copy of the object
* While using = as in the example it creates a reference to same memory location but with different name
*/
import java.io.PrintStream;
public class CloneTest {
public static void main(String[] arrstring) throws Exception {
/*t1*/TestClass testClass1 = new TestClass(8798, 540.321);
/*t2*/TestClass testClass2 = (TestClass)testClass1.clone();
@bansalayush
bansalayush / GetImageSize.java
Created March 7, 2017 06:33
Get size of selected image in bytes
private void showFileChooser() {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), 2);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="25dp"
android:height="25dp"
android:viewportWidth="490.4"
android:viewportHeight="490.4">
<path
android:fillColor="#000000"
android:pathData="M245.2,490.4c135.2,0,245.2-110,245.2-245.2S380.4,0,245.2,0S0,110,0,245.2C0,380.4,110,490.4,245.2,490.4z
//in babel //in javascript
const arr1 = ['a','b','c']; var arr1 = ['a', 'b', 'c'];
const arr2 = ['d','e','f']; var arr2 = ['d', 'e', 'f'];
var arr3= [...arr1,...arr2]; var arr3 = [].concat(arr1, arr2);
installation -> npm intsall react-native-truecaller --save
linking -> react-native link react-native-truecaller
and on running react-native run-android
we get the following error which points to react-native-truecaller
```
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/ayushbansal/Sites/cybertron/cybertron-starscream/node_modules/react-native-truecaller/android/build.gradle' line: 5
@bansalayush
bansalayush / convertImages.txt
Created November 13, 2018 13:36
resizing PNG images to use them for iOS development
AppStore supports images of size 40X40, 60X60,58X58, 87X87, 120X120, 180X180 ,1024X1024 and 80X80 (all in pixels).
It might be a tiresome job (for lazy ppl like me ) to resize a given image to above supported formats using Preview.
This is the reason god invented CLI. To avoid pixel-ation of images let's use an 1024X1024 image to be resized . Let's create
8 copies of this image.
Rename the original image to 1024.png
Using the following commands to create multiple copies
cp 1024.png 80.png
cp 1024.png 60.png
cp 1024.png 180.png
@bansalayush
bansalayush / MirrorOfTree.psudocode
Created February 1, 2019 18:56
creating mirror of a tree
Given a Binary Tree, convert it into its mirror.
1 1
/ \ / \
3 2 ====> . 2 . 3
/ \ / \
5 4 4 5
traverse(node){
@bansalayush
bansalayush / isTreeBalanced.c
Last active February 1, 2019 19:06
Calculating height of a Binary Tree :) Check if a tree is balanced or not :)
Diff in left and right height should be less than or equal to 1.
int traverse(node){
if(node == null)
return 0;
int leftHeight = traverse(node->left);
int rightHeight = traverse(node->right);
isBalanced(leftHeight,rightHeight,node);
return max(leftHeight,rightHeight) + 1;
}
@bansalayush
bansalayush / repositoryPattern.txt
Created February 19, 2019 19:37
Repository pattern
It gives software developers a mediation layer between the domain of the application and the raw data fetched
from the data source.
Repository pattern is a great idea, and it’s what Store is based on: instead of accessing the network layer directly,
the library should be invoked, giving a wide range of benefits.
One of them is the possibility of persisting the data so that it can be accessed while offline.
This brings us to the next step, the record duration policy: within Store it’s possible to declare how long the data
should persist.
There is control over whether to fetch fresh data when what’s currently on disk is stale, or not.
Store also provides total freedom on how to fetch, parse and persist data, while still giving good defaults.
String strings = Utils.decodeString(mChannelObj.getDescription());
tvDescription.setVisibility(VISIBLE);
descriptionDivView.setVisibility(VISIBLE);
SpannableStringBuilder span = new SpannableStringBuilder(strings);
Pattern webPattern = Patterns.WEB_URL;
Matcher matcher = webPattern.matcher(Utils.decodeString(mChannelObj.getDescription()));
while (matcher.find()) {
ClickableSpan clickableSpan = new ClickableSpan() {
@Override