Skip to content

Instantly share code, notes, and snippets.

@antoni
antoni / sudo-keepalive-example.sh
Created January 6, 2019 13:14 — forked from cowboy/sudo-keepalive-example.sh
Bash: Sudo keep-alive (good for long-running scripts that need sudo internally but shouldn't be run with sudo)
#!/bin/bash
# Might as well ask for password up-front, right?
sudo -v
# Keep-alive: update existing sudo time stamp if set, otherwise do nothing.
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
# Example: do stuff over the next 30+ mins that requires sudo here or there.
function wait() {
#!/usr/bin/env bash
: ' Usage:
bash <(wget --quiet --output-document=- https://gist.githubusercontent.com/antoni/0baa816895d7155c7f41e155e2ee7f70/raw)
'
# Replaces $1 with $2 in the origin named 'origin' of Git repo
# Should be executed from inside of the repository folder
function replace_in_origin() {
### Keybase proof
I hereby claim:
* I am antoni on github.
* I am antoni (https://keybase.io/antoni) on keybase.
* I have a public key ASBjyuQy5Z1RKEScj1d1U_KBa_wNzjunfSWleyf_ITIoLAo
To claim this, I am signing this object:
@antoni
antoni / tmux-cheats.md
Created February 11, 2018 21:39 — forked from Starefossen/tmux-cheats.md
My personal tmux cheat sheet for working with sessions, windows, and panes. `NB` I have remapped the command prefix to `ctrl` + `a`.

Sessions

New Session

  • tmux new [-s name] [cmd] (:new) - new session

Switch Session

  • tmux ls (:ls) - list sessions
  • tmux switch [-t name] (:switch) - switches to an existing session
@antoni
antoni / json_stringify_once.js
Created August 1, 2017 12:00
Dumps an object in JSON. Works with circular JSON structures
// Dumps an object in JSON. Works with circular structures like:
//
// var o = {};
// o.o = o;
JSON.stringifyOnce = function(obj, replacer, indent){
var printedObjects = [];
var printedObjectKeys = [];
function printOnceReplacer(key, value){
if ( printedObjects.length > 2000){ // browsers will not print more than 20K, I don't see the point to allow 2K.. algorithm will not be fast anyway if we have too many objects
// C++ includes used for precompiling -*- C++ -*-
// Copyright (C) 2003-2013 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
@antoni
antoni / custom_json.go
Created July 12, 2017 14:25 — forked from mdwhatcott/custom_json.go
Example of implementing MarshalJSON and UnmarshalJSON to serialize and deserialize custom types to JSON in Go. Playground: http://play.golang.org/p/7nk5ZEbVLw
package main
import (
"bytes"
"encoding/json"
"fmt"
"strconv"
)
func main() {

Keybase proof

I hereby claim:

  • I am antoni on github.
  • I am antoni (https://keybase.io/antoni) on keybase.
  • I have a public key whose fingerprint is 44F5 9989 3969 BCE2 A47F 80A8 0F99 31FF F386 106B

To claim this, I am signing this object:

@antoni
antoni / release-android-debuggable.md
Created May 22, 2017 15:12 — forked from nstarke/release-android-debuggable.md
How to make a Release Android App debuggable

How to make a Release Android App debuggable

Let's say you want to access the application shared preferences in /data/data/com.mypackage.
You could try to run adb shell and then run-as com.mypackage ( or adb shell run-as com.mypackge ls /data/data/com.mypackage/shared_prefs), but on a production release app downloaded from an app store you're most likely to see:

run-as: Package 'com.mypackage' is not debuggable
@antoni
antoni / install_mosh_locally.sh
Last active May 18, 2017 14:40 — forked from lazywei/install_mosh_locally.sh
Install mosh server without root permission
#!/bin/sh
# this script does absolutely ZERO error checking. however, it worked
# for me on a RHEL 6.3 machine on 2012-08-08. clearly, the version numbers
# and/or URLs should be made variables. cheers, zmil...@cs.wisc.edu
mkdir mosh
cd mosh