Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@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
@antoni
antoni / hashmap.sh
Created May 16, 2017 11:54
Hashmap in Bash
declare -A hashmap
hashmap["key"]="value"
hashmap["key2"]="value2"
echo "${hashmap["key"]}"
for key in ${!hashmap[@]}; do echo $key; done
for value in ${hashmap[@]}; do echo $value; done
@antoni
antoni / JsonServer.py
Created April 26, 2017 10:38
JSON server, which serves local directory static files according to file's basename.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
JSON server, which serves local directory static files according to file's basename.
echo '{"key": "valuy"}' > resp.json
python -m JsonServer
curl http://localhost:8000/resp
"""
@antoni
antoni / install_google_cloud_sdk.sh
Created April 13, 2017 11:23
A script for installing Google Cloud SDK on Ubuntu.Debian
#!/usr/bin/bash
# Create an environment variable for the correct distribution
export CLOUD_SDK_REPO="cloud-sdk-$(lsb_release -c -s)"
# Add the Cloud SDK distribution URI as a package source
echo "deb https://packages.cloud.google.com/apt $CLOUD_SDK_REPO main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
# Import the Google Cloud Platform public key
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
@antoni
antoni / ns-inet.sh
Created August 27, 2016 18:11 — forked from dpino/ns-inet.sh
Setup a network namespace with Internet access
#!/usr/bin/env bash
set -x
NS="ns1"
VETH="veth1"
VPEER="vpeer1"
VETH_ADDR="10.200.1.1"
VPEER_ADDR="10.200.1.2"