Skip to content

Instantly share code, notes, and snippets.

View chris-piekarski's full-sized avatar

Christopher Piekarski chris-piekarski

  • Boulder, CO
  • 13:55 (UTC)
View GitHub Profile
@chris-piekarski
chris-piekarski / android_wifi_status
Last active August 29, 2015 13:56
Properly control Android service state based on Wifi status
private void registerConnectivityChange() {
BroadcastReceiver connectionReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// When just using the ConnectivityManager you can get identical intents
// twice within one second. So we need to use the WifiManager & ConnectivityManager
// to determine true state
if (intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
NetworkInfo networkInfo = intent
@chris-piekarski
chris-piekarski / aosp_pid
Last active August 29, 2015 13:57
Android Process Pid
android.os.Process.myPid()
android.os.Process.killProcess(android.os.Process.myPid())
@chris-piekarski
chris-piekarski / x11_ssh
Last active August 29, 2015 13:58
Headless Ubuntu X11 SSH Tunnel
On SSH server make sure the sshd config file contains "X11Forwarding yes" (/etc/ssh/sshd_config).
On the client add -X flag to ssh command ( ssh -X myusername@myhost.com ). Then simply run X11 programs.
@chris-piekarski
chris-piekarski / python_create_cert
Created May 7, 2014 16:51
Generate Self Signed Cert w/Python
import sys, os
from OpenSSL import crypto, SSL
from socket import gethostname
from pprint import pprint
from time import gmtime, mktime
from os.path import exists, join
CERT_FILE = "apache.crt"
KEY_FILE = "apache.key"
@chris-piekarski
chris-piekarski / debain_custom_service
Last active August 29, 2015 14:02
Debian - Add Service
sudo vi /etc/init.d/cjp
sudo chmod +x /etc/init.d/cjp
#if you want it to run at startup
sudo update-rc.d cjp defaults
#to remove
sudo update-rc.d -f cjp remove
#start and stop at will
@chris-piekarski
chris-piekarski / django_notes
Last active August 29, 2015 14:03
django notes
#get version
python -c "import django; print(django.get_version())"
#create a project
django-admin.py startproject mysite
#run development server
python manage.py runserver OR python manage.py runserver 8080 OR python manage.py runserver 0.0.0.0:8000
#create databse tables from INSTALLED_APPS models
@chris-piekarski
chris-piekarski / ubuntu_oracle_jdk
Created July 4, 2014 01:18
Ubuntu Oracle JDK Install
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
Oracle JDK 6
sudo apt-get install oracle-java6-installer
Oracle JDK 7
sudo apt-get install oracle-java7-installer
@chris-piekarski
chris-piekarski / syslog_real_time_crunch
Created July 22, 2014 17:29
Crunch syslog file in real-time
tail -f /var/log/syslog | stdbuf -oL cut -d'|' -f2 | tee times.txt
@chris-piekarski
chris-piekarski / jce_providers
Created September 23, 2014 17:22
Listing all JCE providers and the algorithms they support
Provider[] providers = Security.getProviders();
for (Provider p : providers) {
System.out.printf("%s/%s/%f\n", p.getName(), p.getInfo(),
p.getVersion());
Set<Service> services = p.getServices();
for (Service s : services) {
System.out.printf("\t%s/%s/%s\n", s.getType(),
s.getAlgorithm(), s.getClassName());
@chris-piekarski
chris-piekarski / android:layout_width
Created October 7, 2014 18:42
Layout Width/Height Constants
public static final int FILL_PARENT
Added in API level 1
Special value for the height or width requested by a View. FILL_PARENT means that the view wants to be as big as its parent, minus the parent's padding, if any. This value is deprecated starting in API Level 8 and replaced by MATCH_PARENT.
Constant Value: -1 (0xffffffff)
public static final int MATCH_PARENT
Added in API level 8