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 / ct.py
Created February 16, 2017 22:58
Time Puncher
#!/usr/local/bin/python
import sys
import ast
import inspect
import keyring # for storing password in OS X Keychain
from datetime import datetime
from subprocess import check_output
from astunparse import unparse
from grab import Grab
@Palisand
Palisand / ReactTextInputManager.java
Last active October 8, 2017 21:28
Changes for scroll-to-cursor functionality.
import android.text.Layout;
...
private class ReactSelectionWatcher implements SelectionWatcher {
private ReactEditText mReactEditText;
private EventDispatcher mEventDispatcher;
private int mPreviousSelectionStart;
private int mPreviousSelectionEnd;
@Palisand
Palisand / ReactTextInputSelectionEvent.java
Last active October 11, 2017 16:17
Changes for scroll-to-cursor functionality.
/**
* Event emitted by EditText native view when the text selection changes.
*/
/* package */ class ReactTextInputSelectionEvent
extends Event<ReactTextInputSelectionEvent> {
private static final String EVENT_NAME = "topSelectionChange";
private int mSelectionStart;
private int mSelectionEnd;
@Palisand
Palisand / RCTTextSelect.h
Last active October 9, 2017 21:07
Changes for scroll-to-cursor functionality.
/**
* Object containing information about a TextInput's selection.
*/
@interface RCTTextSelection : NSObject
@property (nonatomic, assign, readonly) NSInteger start;
@property (nonatomic, assign, readonly) NSInteger end;
/* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */
@property (nonatomic, assign, readonly) CGPoint cursorPosition;
@Palisand
Palisand / RCTTextSelection.m
Last active October 9, 2017 21:14
Changes for scroll-to-cursor functionality.
@implementation RCTTextSelection
/* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */
- (instancetype)initWithStart:(NSInteger)start end:(NSInteger)end cursorPosition:(CGPoint)cursorPosition
/* <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */
{
if (self = [super init]) {
_start = start;
_end = end;
/* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */
@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];
/* <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */
@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 / 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 / .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 / 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