Skip to content

Instantly share code, notes, and snippets.

@HyperGrapher
HyperGrapher / compress_video
Created August 22, 2024 10:26 — forked from trvswgnr/compress_video
portable shell script to compress videos with ffmpeg
#!/bin/sh
print_usage() {
echo "usage: compress_video <input_file>"
echo "supported formats: mp4, webm, mkv, mov, avi, flv"
}
get_extension() {
f="${1##*/}"
case "$f" in
@HyperGrapher
HyperGrapher / check-routes.rb
Created February 19, 2022 07:25
check unused rails routes
# Download this into the root folder of your Rails project & run it with "ruby check-routes.rb"
require_relative "config/environment"
Rails.application.eager_load!
results =
Rails.application.routes.routes.map(&:requirements).reject(&:empty?).map do |r|
name = r[:controller].camelcase
controller = "#{name}Controller"
@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)
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()
// 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
@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
@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);
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 / 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());
}
});
@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;