Skip to content

Instantly share code, notes, and snippets.

View kevinthecity's full-sized avatar

Kevin Grant kevinthecity

  • LatticeHR
  • New York City
View GitHub Profile
@kevinthecity
kevinthecity / ag-replace.sh
Created May 26, 2023 20:15
Find / Replace in directory
# ag <https://github.com/ggreer/the_silver_searcher>
# requires ag -> brew install the_silver_searcher
# usage: ag-replace.sh [search] [replace]
# caveats: will choke if either arguments contain a forward slash
# notes: will back up changed files to *.bak files. Remove the second line if you'd like to keep them
ag -0 -l $1 | xargs -0 sed -ri.bak -e "s/$1/$2/g";
git clean -f '**/*.bak';
@kevinthecity
kevinthecity / find_unused_keys.sh
Created May 26, 2023 19:43
Script for finding keys in a folder directory
#!/bin/bash
# brew install the_silver_searcher https://github.com/ggreer/the_silver_searcher
# Add this script somewhere, and update permissions: chmod +x find_unused_keys.sh
# usage: ./find_unused_keys.sh keys.csv [optional: /path/to/search/]
# column 1 should be the key, column 2 should be the team name
CSV_FILE=$1
@kevinthecity
kevinthecity / .lua
Last active March 14, 2023 02:47
Simple repair mod for Project Zomboid.
-- Project forked from existing repair mod https://steamcommunity.com/sharedfiles/filedetails/?id=2852867235&searchtext=better+repair
-- Docs https://projectzomboid.com/modding/zombie/characters/package-summary.html
local ISFixAction_perform = ISFixAction.perform
-- Random chance to return true if the repair counter should be frozen (e.g. this item can no longer break)
local function shouldFreezeRepairCount()
local chance = SandboxVars.PRM.stopCounterChance
if chance == 0 then return false end
local a = ZombRand(0, 101)
local b = 100 - chance
/**
* Shake a view with a preset cycle interpolater
*
* @param view
* the view to shake
*/
public static void shakeIt(final View view) {
if (view != null) {
Animation shakeAnimation = new TranslateAnimation(0, 10, 0, 0);
shakeAnimation.setDuration(300);
https://drive.google.com/file/d/0B31CyA6eg0M6NU9sNWpxMkJham8/edit?usp=sharing
<!--
Copyright (C) 2014 Google Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
@kevinthecity
kevinthecity / gist:11192121
Last active August 29, 2015 14:00
Recursively remove children from ViewGroups
public static void removeAllViews(final ViewGroup viewGroup) {
while (viewGroup.getChildCount() != 0) {
boolean childrenHaveChildren = false;
for (int i = 0; i < viewGroup.getChildCount(); i++) {
final View child = viewGroup.getChildAt(i);
if (child instanceof ViewGroup) {
/**
* Converts a DP value to a PX value.
*
* @param context
* the context to use.
* @param dp
* the DP value to convert.
* @return the converted PX value.
*/
public static int getPxFromDp(Context context, float dp) {
@kevinthecity
kevinthecity / gist:8643630
Created January 27, 2014 05:23
To prevent appending the comma to the last item
int[] array = {1, 2, 3...};
StringBuilder builder = new StringBuilder();
for (int i : array) {
if (builder.length() != 0) {
builder.append(",");
}
builder.append(i);
}
@kevinthecity
kevinthecity / gist:5287801
Last active December 15, 2015 16:18
Using a ScheduledFuture with an Executor
private final ScheduledExecutorService mExecutor = Executors.newSingleThreadScheduledExecutor();
private ScheduledFuture<?> mScheduled;
public void onCallback() {
if (mScheduled != null) {
mScheduled.cancel(true);
}
mScheduled = mExecutor.schedule(new Runnable() {
@Override