Skip to content

Instantly share code, notes, and snippets.

Avatar

Lope Chupijay Emano z0lope0z

View GitHub Profile
@z0lope0z
z0lope0z / post-merge.rb
Created Mar 18, 2016
git hook for sending email regarding migration changes
View post-merge.rb
#!/usr/bin/env ruby
require 'pony'
def send_mail(to, from, message)
Pony.mail({
:to => to,
:via => :smtp,
:from => from,
:subject => 'new migrations detected for master branch',
:body => message,
@z0lope0z
z0lope0z / post-merge.rb
Created Mar 18, 2016
git hook for sending email regarding migration changes
View post-merge.rb
#!/usr/bin/env ruby
require 'pony'
def send_mail(to, from, message)
Pony.mail({
:to => to,
:via => :smtp,
:from => from,
:subject => 'new migrations detected for master branch',
:body => message,
@z0lope0z
z0lope0z / pr.md
Last active Aug 29, 2015
PR notes
View pr.md

This PR has many changes so I'd like to break it down, especially since I've bundled multiple tickets (bad practice, just this once I promise! huhu)

Breakdown

Use of DTOs(Data Transfer Objects)

DTOs are currently used as a contracts for views as well as a bundling object when methods need to return multiple objects of different types (java doesn’t support returning of tuples)

syncData() now returns a Data Transfer Object that bundles {orderItem, suggestionMap, and replacementMap} so that inheriting classes can just override, call super method and retrieve the updated data

Introduction of command pattern + builder pattern for each user interaction

@z0lope0z
z0lope0z / gist:b1c60642749b83e9603f
Created May 22, 2015
NetworkUtil/Connectivity, posting here because too useful
View gist:b1c60642749b83e9603f
/**
* Check device's network connectivity and speed
* taken from https://gist.github.com/emil2k/5130324
* @author emil http://stackoverflow.com/users/220710/emil
*
*/
public class Connectivity {
/**
* Get the network info
@z0lope0z
z0lope0z / gist:9876d27061744e234c42
Created May 5, 2015
GZipped Request in OkHttp using Interceptors
View gist:9876d27061744e234c42
// Not sure about this but uses a combination of the two:
// https://github.com/square/okhttp/issues/350
// https://android.googlesource.com/platform/external/okhttp/+/e78f117bcbd6b57d783737107f445ef75ecb474a/samples/guide/src/main/java/com/squareup/okhttp/recipes/RequestBodyCompression.java
public Response proceedGzip(Interceptor.Chain chain) throws IOException {
Request originalRequest = chain.request();
Request compressedRequest = originalRequest.newBuilder()
.header("Content-Encoding", "gzip")
.method(originalRequest.method(), requestBodyWithContentLength(gzip(originalRequest.body())))
.build();
return chain.proceed(compressedRequest);
@z0lope0z
z0lope0z / gist:449e85d2486acac29437
Created Apr 30, 2015
Dagger 2.0 + Android Studio 1.2
View gist:449e85d2486acac29437
//http://siphon9.net/loune/2015/04/dagger-2-0-android-migration-tips/
//http://stackoverflow.com/questions/29703480/dagger-2-and-android-studio-working-but-cant-see-generated-classes
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
buildscript {
repositories {
mavenCentral()
}
@z0lope0z
z0lope0z / gist:8b5dc3ad01b05936d839
Created Apr 21, 2015
ObscuredSharedPreferences.java by RightHandedMonkey
View gist:8b5dc3ad01b05936d839
import java.io.UnsupportedEncodingException;
import java.util.Map;
import java.util.Set;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.PBEParameterSpec;
@z0lope0z
z0lope0z / gist:0bfe1f49414bb11a9f93
Created Jan 26, 2015
Stop an EditText from getting focused on activity launch
View gist:0bfe1f49414bb11a9f93
from: http://stackoverflow.com/questions/1555109/stop-edittext-from-gaining-focus-at-activity-startup/1612017#1612017
Add these properties to any ViewGroup in your layout
android:focusable="true"
android:focusableInTouchMode="true"
@z0lope0z
z0lope0z / getDimenInDP.java
Last active Apr 23, 2021
Get screen width and height programmatically in Android
View getDimenInDP.java
// orig: http://stackoverflow.com/questions/6465680/how-to-determine-the-screen-width-in-terms-of-dp-or-dip-at-runtime-in-android
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
float dpHeight = displayMetrics.heightPixels / displayMetrics.density;
float dpWidth = displayMetrics.widthPixels / displayMetrics.density;
@z0lope0z
z0lope0z / gist:fe211d4c07975ff5f692
Created Nov 28, 2014
Getting geo coordinates from old google maps API using Cell Tower ID, Location Area Code, Mobile Country Code, and Mobile Network Code
View gist:fe211d4c07975ff5f692
/**
* Shamelessly extracted from
* https://code.google.com/p/mwop/source/browse/sandbox/server/mwop-server/src/com/mwop/server/cellID/CellIDResolver.java?r=18
*/
public static Coordinate transform(int cellID, int lac, int mcc, int mnc) throws IOException {
URL providerAddress = new URL("http://www.google.com/glm/mmap");
HttpURLConnection connection = (HttpURLConnection) providerAddress.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.connect();