Tuesday, November 29, 2016

libasutils - Some c++ utilities that come in handy at times

Latest project involves c++.  I needed some utilities and I needed them my way!  I used a bunch of helper libraries and also rolled some of my own.  Some useful stuff, I'm sure there are others that do the same and maybe part of the STD has it but I wanted a bit of learning as well.  Things it currently has:

  1.  Http server - thin c++ wrapper around gnu libmicrohttpd
  2.  EPOLL high performance sockets for client/server 
  3.  Thread pool
  4.  Utils - sha1 (wraps boosts), timestamps, timestamp converter, split
  5.  Buffered reader and writer

It's linux only.

https://github.com/asharif/libasutils

Wednesday, April 6, 2016

setting up ssh tunnel

Just so I don't forget in my old age.  Here is how to setup an ssh tunnel:

ssh user@remote -L 8081:remote:8080 -N

this sets up a tunnel that forwards all calls to localhost:8081 to remote:8080.  If you want the command to give you back your terminal session you need a -f flag

Thursday, February 4, 2016

make-ios - peace out XCODE IDE!

So awhile ago, I got so frustrated with Android Studio and the crappy build system that is gradle, that I decided to create a Makefile so I understood what was going on (http://orphanware.blogspot.com/2014/08/androids-bloated-build-system-be-damned.html). It turned out the actual commands to run and create an Android project are not hard, but rather interesting.

Anyway, more recently I decided to do the same with iOS.  The results were MUCH simpler than the Android version since android has to convert java *.class files to a *.dex file, among other tedious steps. You still need to download XCODE from the App Store as the only way that I'm aware of getting the iOS SDK is to download the IDE.  Anyway without further blabbering.  Will upload as sample app to github in a later post:


SRC=`pwd`/src/objc/m/** INC=-I`pwd`/src/objc/h/ LIB=-l xml2.2 `pwd`/lib/dummylib -l z.1.2.5 FRAMEWORKS=-framework Foundation -framework UIKit -framework AVFoundation -framework CoreGraphics ISYSROOT=-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/ ARCH64=-arch arm64 -miphoneos-version-min=6 ARCHV7=-arch armv7 -miphoneos-version-min=6 TMP_ARCH64_BIN=tmp/ioscliapp_arch64 TMP_ARCHV7_BIN=tmp/ioscliapp_archv7 BIN=bin/Payload/iosapp.app/iosapp #this is just the string value that you find in your OSX keychain for your certificate CERT=`cat /etc/ios_cert_name` BUNDLEID="org.orphanware.iosapp" default: pre arch64 archv7 post pre: @mkdir -p bin/Payload/iosapp.app/ @mkdir -p tmp/obj/ @cp etc/Info.plist bin/Payload/iosapp.app/ @cp etc/ProvisionProfile.mobileprovision bin/Payload/iosapp.app/embedded.mobileprovision post: @lipo -create $(TMP_ARCH64_BIN) $(TMP_ARCHV7_BIN) -output $(BIN) @codesign -f -s "$(CERT)" --entitlements etc/entitlements.plist bin/Payload/iosapp.app @cd bin/; zip -qr iosapp.ipa Payload/ arch64: @gcc -Wall -g -c -ObjC $(SRC) $(INC) $(ISYSROOT) $(ARCH64) @mv *.o tmp/obj/ @gcc -o $(TMP_ARCH64_BIN) tmp/obj/** -ObjC $(LIB) $(ISYSROOT) $(FRAMEWORKS) $(ARCH64) @rm tmp/obj/* archv7: @gcc -Wall -g -c -ObjC $(SRC) $(INC) $(ISYSROOT) $(ARCHV7) @mv *.o tmp/obj/ @gcc -o $(TMP_ARCHV7_BIN) tmp/obj/** -ObjC $(LIB) $(ISYSROOT) $(FRAMEWORKS) $(ARCHV7) @rm tmp/obj/* clean: @rm -rf tmp/ @rm -rf bin/*

Friday, August 14, 2015

jtv - bash-fu for top cpu consuming threads in jvm along with the output from jstack

So if you ever find yourself needing to find out what threads in a JVM are taking up lots of CPU you can run this little bash script.  It is super stupid and ugly but it gets the job done!



https://github.com/asharif/jtv

Thursday, July 9, 2015

Skip host key checking with ssh and scope

Just a reminder cause I can't remember syntax for the life of me!

ssh -o StrictHostKeychecking=no -o UserKnownHostsFile=/dev/null

Friday, January 16, 2015

Get number of threads in a *nix process

Just so I don't forget this:

ps -L -o pid= -p  | wc -l

on OSX(also works on linux I believe)

NUM=`ps M  | wc -l | xargs` && expr $NUM - 1

Thursday, August 28, 2014

make-android - Android bloated build system be damned!

Lately I've been working on some Android stuff.  I hadn't worked on android in awhile so I downloaded their new android studio instead of the eclipse ADT.....

Ya I know it's in beta, but are you kidding me?  A sample hello world application took like 30 seconds to build with gradle.  And gradle itself is a bloated tool.  As soon as I attempt to type

$ gradle

in terminal it makes my macbook pro sound like it's taking off into space.

So I tried going back to the ant system in ADT. There I ran into problems as the AndroidManifest.xml now lives in a different place. I tried to look and fix the 1500 line xml garbage under

$ANDROID_HOME/tools/ant/build.xml 

and quickly said WTF.

Then I said you know what I am not going to live like this.  Screw you Google, your build tools are bloated abominations I will make my own.  It turns out that building for android without all the abstractions of gradle and ant is WAY faster and to me more elegant.

The native tools 'aapt' and 'dx' helps us here.


$ANDROID_HOME/build-tools/x.x.x/aapt
$ANDROID_HOME/build-tools/x.x.x/dx


So here is a example using good old Makefile. Yes I know I could of used ant to have incremental builds, but I can do the same in make (future post) without having to spawn a new jvm instance!

https://github.com/asharif/make-android

A lot of it as you can see is to support google play services. I can't believe Googles way is to add a project in eclipse! Anyway a gradle project that took 1 minutes to build on my late 2013 Macbook Pro now takes 7 seconds. That and my laptop doesn't turn into hot coal. Also notice how I left out the part about the keys,keystore and signing. I figure that stuff is outside the scope and regular java stuff.

Enjoy!