Skip to content

Instantly share code, notes, and snippets.

View andrew-codechimp's full-sized avatar

Andrew Jackson andrew-codechimp

View GitHub Profile
@andrew-codechimp
andrew-codechimp / gist:3351362
Last active April 3, 2018 11:59
[Launch Android Preference Fragment with only one header] #Android
// Handles the user's menu selection.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_settings:
@SuppressWarnings("rawtypes")
Class c = Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB ? PreferencesActivity.class : FragmentPreferences.class;
Intent i = new Intent(this, c);
@andrew-codechimp
andrew-codechimp / OngoingNotification.java
Last active April 3, 2018 11:59
[Ongoing Notification without status bar icon] #Android
package your.package.name;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.TaskStackBuilder;
public class OngoingNotification {
@andrew-codechimp
andrew-codechimp / gist:647d4ba5c2862f02319d
Last active April 3, 2018 12:00
[getAccount] #Android
private Account getAccount(String accountName) {
AccountManager manager = (AccountManager) getActivity().getSystemService(Activity.ACCOUNT_SERVICE);
Account[] list = manager.getAccounts();
for (Account account : list) {
if (account.type.equalsIgnoreCase("com.google")) {
if (account.name.equalsIgnoreCase(accountName)) {
return account;
}
}
}
@andrew-codechimp
andrew-codechimp / build.gradle
Last active May 9, 2017 13:06
Reference project level debug.keystore within Gradle build
...
signingConfigs {
debug {
storeFile rootProject.file('debug.keystore')
storePassword "android"
keyAlias "androiddebugkey"
keyPassword "android"
}
release
}
@andrew-codechimp
andrew-codechimp / Jenkins Git Publisher
Last active May 24, 2017 18:59
Gradle Versioning for Wear with Jenkins
Tag To Push - v${BUILD_NUMBER}0
Tag Message - Version ${BUILD_NUMBER}0
@andrew-codechimp
andrew-codechimp / keybase.md
Created September 19, 2017 11:57
keybase.md

Keybase proof

I hereby claim:

  • I am andrew-codechimp on github.
  • I am codechimp (https://keybase.io/codechimp) on keybase.
  • I have a public key ASBNplcLzvfVz0837RbWQpxavZ1KAwI8wNnCb8tDmebqqgo

To claim this, I am signing this object:

@andrew-codechimp
andrew-codechimp / module build.gradle
Created June 4, 2018 10:09
[Gradle load Android signing.properties] #Android #Gradle
android {
...
signingConfigs {
debug {
storeFile file("debug.keystore")
storePassword "android"
keyAlias "androiddebugkey"
keyPassword "android"
}
release
@andrew-codechimp
andrew-codechimp / configuration.yaml
Last active January 9, 2020 09:43
HA Twitter Followers Sensor
sensor:
- platform: rest
resource: https://cdn.syndication.twimg.com/widgets/followbutton/info.json?screen_names=AndrewCodeChimp
name: Twitter Followers
value_template: '{{ value_json[0].followers_count }}'
scan_interval: 43200 # Every 12 hours in seconds
@andrew-codechimp
andrew-codechimp / arrayunique.swift
Last active February 5, 2020 11:50
[Get unique items in an array based on hash] #Swift
extension Sequence where Iterator.Element: Hashable {
func unique() -> [Iterator.Element] {
// Usage
// print(array.unique()) // prints: [1, 2, 3]
var seen: Set<Iterator.Element> = []
return filter { seen.insert($0).inserted }
}
}
@andrew-codechimp
andrew-codechimp / configuration.yaml
Created March 30, 2020 09:25
Portainer API Home Assistant Command Line Switch Example
...
switch:
- platform: command_line
switches:
portainer_transmission:
command_on: "/bin/bash /config/portainer_transmission_start.sh"
command_off: "/bin/bash /config/portainer_transmission_stop.sh"
command_state: "/bin/bash /config/portainer_transmission_state.sh"
friendly_name: "Portainer Transmission"
...