Skip to content

Instantly share code, notes, and snippets.

View px-amaac's full-sized avatar

Aaron McIntyre px-amaac

View GitHub Profile
@px-amaac
px-amaac / usinglocation.java
Created October 1, 2015 20:14
activity that uses the location client
public class SplashActivity extends BaseActivity implements LocationListener {
// Splash screen timer
private static int SPLASH_TIME_OUT = 1000;
private LocationClient mLocationClient;
private Long mStartTime;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@px-amaac
px-amaac / MainActivity.java
Last active August 29, 2015 14:24
AudioPlayerService
@Override
protected void onResume() {
super.onResume();
Intent mediaIntent = new Intent(this, NowPlayingService.class);
startService(mediaIntent);
if (mNowPlayingService == null)
bindService(mediaIntent, mServiceConnection, Context.BIND_AUTO_CREATE);
}
@px-amaac
px-amaac / Host.java
Last active August 29, 2015 14:24
Problem with parcelable data
public class Host implements Parcelable {
@Expose
private String id;
@SerializedName("display_name")
@Expose
private String displayName;
@Expose
private String username;
@Expose
private String image;
@px-amaac
px-amaac / Deserializer.java
Created June 24, 2015 09:19
deserializer for dealing with lines 18-24 and 45-46
public class JsonDeserializer<T> implements com.google.gson.JsonDeserializer<T> {
@Override
public T deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
Type genericClass = ((ParameterizedType) typeOfT).getActualTypeArguments()[0];
if(genericClass != Boolean.class) {
if (json.isJsonPrimitive()) {
JsonPrimitive jsonPrimitive = json.getAsJsonPrimitive();
if(jsonPrimitive.isBoolean()) {
return null;
@px-amaac
px-amaac / A.JSON
Last active August 29, 2015 14:23
Deserializer
{
"Airtime": {
"start": "18:30:00",
"end": "19:30:00",
"weekday": "1"
},
"id": "150",
"title": "Le Show",
"short_name": "leshow",
"full_description": "<p>From Firesign Theater to Spin Tap, from Saturday Night Live to the Simpsons, Harry Shearer's done it all. Now hear the world through a new prizm, Le Show with Harry Shearer.<\/p><p>Le Show airs Monday evenings at 6:30pm following Moyer's &amp; Co.&nbsp;<\/p>",
@px-amaac
px-amaac / file.cpp
Created April 15, 2015 05:25
iterate map
std::map<std::string, Expression*> *param_map = getParamMap();
cout << "printing param keys" << endl;
for(auto it = param_map->begin(); it != param_map->end(); ++it)
{
cout << it->first << endl;
cout << "parameter map size " << param_map->size() << endl;
}
var net = require('net');
var HOST = '127.0.0.1';
var PORT = 4242;
var server = net.createServer();
server.listen(PORT, HOST);
server.on('connection', function(sock) {
console.log('CONNECTED');
@px-amaac
px-amaac / BaseStaggeredGrid.java
Last active August 29, 2015 14:11
Error message
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View root = inflater.inflate(R.layout.activity_staggered_grid, container, false);
mGridView = (StaggeredGridView) root.findViewById(R.id.grid_view);
createOrRestoreGridData(savedInstanceState);
mGridView.setOnItemClickListener(this);
mGridView.setOnScrollListener(this);
return root;
}
I am getting all photos through the tags table where tags has a search key and search value. I order them.
Is there a way to only get uniques? Right now if i have 2 tags with the same name it will return the same photo twice.
@photos = Photo.joins(:tags).where(tags: { key: params[:searchkey], value: params[:searchvalue] }).order("created_at DESC")
@photos = Photo.joins(:tags).where(:tags => { :key => params[:search_key], :value => params[:search_value] }).order("created_at DESC")
<CheckBox
android:id="@+id/selected_check_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@drawable/default_checkbox_btn"
android:text="Select"
android:layout_marginLeft="4dp"
android:layout_marginRight="32dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"/>