Skip to content

Instantly share code, notes, and snippets.

View fnk0's full-sized avatar

Marcus Gabilheri fnk0

  • Snap
  • Los Angeles, CA
View GitHub Profile
@fnk0
fnk0 / PrefManager.java
Created February 20, 2016 21:31
Simple Preference manager for Android
public final class PrefManager {
static PrefManager singleton = null;
static SharedPreferences preferences;
static SharedPreferences.Editor editor;
private PrefManager() { }
@fnk0
fnk0 / UIIMageExtension.swift
Created October 13, 2015 03:32
Simple UIImage Extension to allow a image to scale and rotate based on Orientantion
import Foundation
import UIKit
extension UIImage {
func scaleAndRotateImage(maxSize: CGFloat) -> UIImage {
let imgRef = self.CGImage
let width = CGFloat(CGImageGetWidth(imgRef))
@fnk0
fnk0 / DividerItemDecoration.java
Created October 11, 2015 21:16
Simple RecyclerView divider item decoration
public class DividerItemDecoration extends RecyclerView.ItemDecoration {
private Drawable mDivider;
private boolean mShowFirstDivider = false;
private boolean mShowLastDivider = false;
public DividerItemDecoration(Context context, AttributeSet attrs) {
final TypedArray a = context.obtainStyledAttributes(attrs, new int[]{android.R.attr.listDivider});
mDivider = a.getDrawable(0);
@fnk0
fnk0 / SquareView.swift
Last active October 11, 2015 21:19
Swift view that will draw a arbitrary number of squares
import Foundation
import UIKit
// This view will render a arbitrary number of squares
@IBDesignable
class SquaresView : UIView {
@IBInspectable var totalSquares : Int = 10
@IBInspectable var numSquares : Int = 10
@IBInspectable var space : CGFloat = 5.0
@fnk0
fnk0 / CalculateCenter.js
Last active October 11, 2015 21:20
Angular factory that calculates the best set of coordinates to center a set of coordiantes in a map
app.factory('calculateCenter', function($window) {
var coordinates = [];
return function(data) {
var num_coords = data.length;
var X = 0.0;
var Y = 0.0;
var Z = 0.0;
for(var i = 0; i < num_coords; i++) {
@fnk0
fnk0 / My Bash profile
Created June 8, 2015 20:46
My bash profile settings for easy setup of a new machine
export PS1="\[\033[36m\]\u\[\033[m\]\[\033[33;1m\]\w\[\033[m\]\$ "
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad
export HISTSIZE=5000
export HISTFILESIZE=5000
export HISTCONTROL=ignoredups
export HISTTIMEFORMAT='%F %T > '
@fnk0
fnk0 / NetworkUtils.java
Last active May 2, 2016 18:46
Utility class to detect if internet is connected and which type of connection
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.telephony.TelephonyManager;
/**
* Created by <a href="mailto:marcus@gabilheri.com">Marcus Gabilheri</a>
*
* @author Marcus Gabilheri
@fnk0
fnk0 / PalindromeBits.java
Last active October 11, 2015 21:22
CodeU Session4
import java.util.HashMap;
// Around 5 minutes (Had to lookup hpw to convert a Integer to binaryString)
// I assumed that the lookup is OK because if I asked the interviewer how to do that they would tell me
public class PalindromeBits {
public static void main(String[] args) {
System.out.println(kthPalindromeInt(8));
System.out.println(kthPalindromeInt(100));
System.out.println(kthPalindromeInt(10000));
@fnk0
fnk0 / FragmentRepos.java
Created May 10, 2015 23:07
First code snippet using rxJava. Retrieves a list of repositories from Github and passes it to a CardsList
public class FragmentRepos extends DefaultListFragment {
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
GithubClient client = new GithubClient(true);
RepoService repoService = client.createService(RepoService.class);
Observable<List<Repo>> repos = repoService.getRepos("fnk0");
AppObservable.bindFragment(this, repos);
repos.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
@fnk0
fnk0 / bash_profile
Created May 10, 2015 05:08
Bash profile
export PS1="\[\033[36m\]\u\[\033[m\]\[\033[33;1m\]\w\[\033[m\]\$ "
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad
export HISTSIZE=5000
export HISTFILESIZE=5000
export HISTCONTROL=ignoredups
export HISTTIMEFORMAT='%F %T > '
export GREP_COLOR='1;32'