Skip to content

Instantly share code, notes, and snippets.

Avatar

Christopher Piekarski chris-piekarski

View GitHub Profile
@chris-piekarski
chris-piekarski / android_wifi_status
Last active Aug 29, 2015
Properly control Android service state based on Wifi status
View android_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 Aug 29, 2015
Android Process Pid
View aosp_pid
android.os.Process.myPid()
android.os.Process.killProcess(android.os.Process.myPid())
@chris-piekarski
chris-piekarski / x11_ssh
Last active Aug 29, 2015
Headless Ubuntu X11 SSH Tunnel
View x11_ssh
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
Generate Self Signed Cert w/Python
View python_create_cert
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"
View debain_custom_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
View 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 Jul 4, 2014
Ubuntu Oracle JDK Install
View ubuntu_oracle_jdk
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 Jul 22, 2014
Crunch syslog file in real-time
View syslog_real_time_crunch
tail -f /var/log/syslog | stdbuf -oL cut -d'|' -f2 | tee times.txt
@chris-piekarski
chris-piekarski / aosp_dimension_types
Created Sep 3, 2014
AOSP Dimension Types (dp, sp, pt, px, mm, in)
View aosp_dimension_types
A dimension value defined in XML. A dimension is specified with a number followed by a unit of measure. For example: 10px, 2in, 5sp. The following units of measure are supported by Android:
dp
Density-independent Pixels - An abstract unit that is based on the physical density of the screen. These units are relative to a 160 dpi (dots per inch) screen, on which 1dp is roughly equal to 1px. When running on a higher density screen, the number of pixels used to draw 1dp is scaled up by a factor appropriate for the screen's dpi. Likewise, when on a lower density screen, the number of pixels used for 1dp is scaled down. The ratio of dp-to-pixel will change with the screen density, but not necessarily in direct proportion. Using dp units (instead of px units) is a simple solution to making the view dimensions in your layout resize properly for different screen densities. In other words, it provides consistency for the real-world sizes of your UI elements across different devices.
sp
Scale-independent Pixels - This
@chris-piekarski
chris-piekarski / jce_providers
Created Sep 23, 2014
Listing all JCE providers and the algorithms they support
View jce_providers
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());