Skip to content

Instantly share code, notes, and snippets.

@HyperGrapher
HyperGrapher / mergeSort.java
Created August 9, 2017 03:47
sorts numbers
import java.util.Scanner;
/**
* This class implements MergeSort
* @author Unknown
*
*/
public class MergeSort {
/** Array for mergeSort*/
private int[] array;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
public class ArrayUtils {
@HyperGrapher
HyperGrapher / MyImageView.java
Created January 3, 2018 23:57
Move and zoom image with Gestures in an android View
package com.develer.circularsliderule;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.View;
@HyperGrapher
HyperGrapher / GetViewHeight.java
Last active January 4, 2018 04:09
Get height of a view in onCreate method (Android)
final LinearLayout layout = (LinearLayout) findViewById(R.id.layout);
final ViewTreeObserver observer= layout.getViewTreeObserver();
observer.addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Log.d("Log", "Height: " + layout.getHeight());
}
});
Picasso.with(context)
.load(model.getNewsImage())
.placeholder(R.drawable.laliga)
.error(R.drawable.premier_league) // will be displayed if the image cannot be loaded
.into(holder.newsImage, new com.squareup.picasso.Callback() {
@Override
public void onSuccess() {
//Success image already loaded into the view
}
@HyperGrapher
HyperGrapher / popupactivity.java
Last active March 31, 2018 01:32
positioning popup menu over the clicked view
public class MainActivity extends AppCompatActivity {
private final static int ONE = 1;
private final static int TWO = 2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
@HyperGrapher
HyperGrapher / hosts
Created November 4, 2018 02:22 — forked from consti/hosts
/etc/hosts to block shock sites etc.
# This hosts file is brought to you by Dan Pollock and can be found at
# http://someonewhocares.org/hosts/
# You are free to copy and distribute this file for non-commercial uses,
# as long the original URL and attribution is included.
#<localhost>
127.0.0.1 localhost
127.0.0.1 localhost.localdomain
255.255.255.255 broadcasthost
::1 localhost
// time and time end
console.time("This");
let total = 0;
for (let j = 0; j < 10000; j++) {
total += j
}
console.log("Result", total);
console.timeEnd("This");
// Memory
from django.db import connection, reset_queries
import time
import functools
def query_debugger(func):
@functools.wraps(func)
def inner_func(*args, **kwargs):
reset_queries()
@HyperGrapher
HyperGrapher / postgres-cheatsheet.md
Created January 6, 2021 09:47 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)