Skip to content

Instantly share code, notes, and snippets.

View donnfelker's full-sized avatar

Donn Felker donnfelker

View GitHub Profile
@donnfelker
donnfelker / build.gradle
Last active January 12, 2024 17:49
gradle properties in Android Studio
// Other build stuff
task ndkBuild(type:Exec) {
if(androidNdkPath != null) {
def ndkBuild = new File(androidNdkPath, 'ndk-build')
commandLine ndkBuild
} else {
// do something else
}
}
@donnfelker
donnfelker / .gitconfig
Last active December 3, 2023 14:16
Git and Fish
[user]
name = Your Name
email = you@youremail.com
[alias]
A = add -A
a = add
aa = add --all
ae = add --edit
ai = add --interactive
amend = commit --amend -C HEAD
@donnfelker
donnfelker / ReceivedCookiesInterceptor.kt
Created October 28, 2023 16:50
OkHttp Cookie Response Interceptor
package com.example.android.http
import android.webkit.CookieManager
import com.example.android.util.BASE_URL // https://example.com/
import logcat.logcat
import okhttp3.Cookie
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.Interceptor
import okhttp3.Response
import okio.IOException
@donnfelker
donnfelker / attached_validator.rb
Last active October 28, 2023 02:51
Custom Active Storage Validator
class AttachedValidator < ActiveModel::EachValidator
# Active Storage validator to ensure that an attachment is attached.
#
# usage:
# validates :upload, attached: true
#
def validate_each(record, attribute, _value)
return if record.send(attribute).attached?
errors_options = {}
@donnfelker
donnfelker / .zshrc
Last active July 1, 2022 13:14
Vanilla ZSH
# Hat tip to Kaushik Gopal for some of this
# make zsh tab completion fix capitalization errors for directories and files
# i don't know if this is required anymore
# autoload -Uz compinit && compinit
# 0 -- vanilla completion (abc => abc)
# 1 -- smart case completion (abc => Abc)
# 2 -- word flex completion (abc => A-big-Car)
# 3 -- full flex completion (abc => ABraCadabra)
@donnfelker
donnfelker / config.fish
Created April 19, 2022 18:01
Fish Config
set -g theme_nerd_fonts yes
set -g theme_display_git_stashed_verbose yes
set -g theme_display_git_master_branch yes
set -g theme_display_git_untracked yes
set -g theme_display_git_dirty yes
set -g theme_display_virtualenv yes
set -Ux EDITOR code --wait
rvm default
@donnfelker
donnfelker / edit.html.erb
Created February 19, 2022 12:00
Stimulus JS Controller to Disable File Attachments in the Trix Editor
<!-- File uploads will be disabled for any trix editor in this div -->
<div data-controller="registrations">
<!-- Other html elements ... -->
<div class="form-group">
<%= form.label :bio, "Bio" %>
<!-- File uploads, and the attachment button will be disabled in this rich text (trix) editor -->
<%= form.rich_text_area :bio %>
</div>
@donnfelker
donnfelker / .gitconfig
Last active August 15, 2021 10:05
My .gitconfig
[user]
name = FirstName LastName
email = you@yourdomain.com
[alias]
A = add -A
a = add
aa = add --all
ae = add --edit
ai = add --interactive
amend = commit --amend -C HEAD
@donnfelker
donnfelker / android-19-circle.yml
Last active March 12, 2021 13:19
Sample CircleCI Configuration For an Android App
#
# Build configuration for Circle CI
#
general:
artifacts:
- /home/ubuntu/your-app-name/app/build/outputs/apk/
machine:
environment:
@donnfelker
donnfelker / CircularTransformation.java
Last active December 2, 2020 20:47
Picasso and CircularTransform Example
import android.graphics.*;
import com.squareup.picasso.Transformation;
/**
* Transforms an image into a circle representation. Such as a avatar.
*/
public class CircularTransformation implements Transformation
{
int radius = 10;