Skip to content

Instantly share code, notes, and snippets.

View Palisand's full-sized avatar

Panaos Alisandratos Palisand

  • RocketVisor Corporation
  • NYC
View GitHub Profile
@Palisand
Palisand / image_transcoding.py
Created January 9, 2022 00:46
Old python code for transcoding images
"""
Helpers to transcode images.
DEPENDENCIES
------------
imagemagick (for converting, already installed)
avconv (for transcoding) sudo apt-get install libav-tools
libx264 (higher encoding quality) sudo apt-get install libavcodec-extra-53
http://askubuntu.com/questions/266663/ffmpeg-resize-could-not-find-codec-parameters
@Palisand
Palisand / convert_to_jpg.py
Created January 9, 2022 00:43
An old convert_to_jpg python script written fresh outta college
"""
convert_to_jpg
Converts image formats that browsers don't commonly support (TIFF, BMP, SGI, RGB, etc.)
to JPGs and stores them in the same directory if an output location is not specified.
Please ignore the following warning:
[swscaler @ 0x7fdabb825e00] deprecated pixel format used, make sure you did set range correctly
Usage:
@Palisand
Palisand / gif_to_mp4.py
Last active January 9, 2022 00:45
An old gif_to_mp4 python script written fresh outta college
"""
gif_to_mp4
Converts GIFs from an input directory to MP4s or a single GIF file to an MP4
and stores them in the same directory if an output location is not specified.
Also, generates a preview image if desired.
Usage:
gif_to_mp4.py <input_file_or_directory> [-o=<output_directory>]
gif_to_mp4.py prev <input_file_or_directory> [-o=<output_directory>] [-p=<output_directory>]
from collections import defaultdict
from typing import Callable, Dict, Iterable, List, Optional
T = TypeVar("T")
U = TypeVar("U")
def group_by(
func: Callable[[T], U],
coll: Iterable[T],
// https://stackoverflow.com/a/54761452/3446870
const {promisify} = require('util');
const readline = require('readline');
async function readlineQuestion(question) {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
@Palisand
Palisand / enumfield.py
Created December 19, 2018 16:20
Django Custom EnumField
from enum import Enum
from typing import List, Optional, Tuple, Type, Union
from django.contrib.auth.models import AbstractUser
from django.db import models
from django.db.backends.base.base import BaseDatabaseWrapper
from django.db.models.expressions import Expression
from django.forms import TypedChoiceField
@Palisand
Palisand / .gitconfig
Last active December 12, 2023 17:44
Git aliases
[alias]
# https://hackernoon.com/lesser-known-git-commands-151a1918a60
# https://gist.github.com/robmiller/6018582
# https://www.atlassian.com/blog/git/advanced-git-aliases
# https://bitbucket.org/durdn/cfg/src/master/.gitconfig?at=master
# https://softwaredoug.com/blog/2022/11/09/idiot-proof-git-aliases.html
# template: "!f() { git ; }; f"
ad = "!f() { git add -u && git st; }; f"
amend = commit --amend
br = rev-parse --abbrev-ref HEAD
@Palisand
Palisand / mapGetFromRegexKeys.js
Created January 27, 2018 18:43
Map with Regex Keys
function getFromRegexKeys(key, map) {
for (let [re, val] of map.entries()) {
if (re.test(key)) {
return val(key.match(re));
}
}
}
const map = new Map([
[/^foo\/(.+)$/, matchResults => matchResults[1]],
@Palisand
Palisand / setPaths.js
Created December 16, 2017 17:47
Mutate object list values to object with values holding property paths
/**
* Convert
*
* foo: {
* bar: ['baz', 'qux'],
* }
*
* to
*
* foo: {
@Palisand
Palisand / RCTTextInput.m
Created October 9, 2017 21:13
Changes for scroll-to-cursor functionality.
- (RCTTextSelection *)selection
{
id<RCTBackedTextInputViewProtocol> backedTextInput = self.backedTextInputView;
UITextRange *selectedTextRange = backedTextInput.selectedTextRange;
return [[RCTTextSelection new] initWithStart:[backedTextInput offsetFromPosition:backedTextInput.beginningOfDocument toPosition:selectedTextRange.start]
end:[backedTextInput offsetFromPosition:backedTextInput.beginningOfDocument toPosition:selectedTextRange.end]
/* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */
cursorPosition:[backedTextInput caretRectForPosition:selectedTextRange.start].origin];
/* <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */