Skip to content

Instantly share code, notes, and snippets.

View mr5z's full-sized avatar
🎯
Focusing

mark mr5z

🎯
Focusing
View GitHub Profile
@mr5z
mr5z / LocalBroadcastManagerActivity.java
Created December 18, 2015 02:25
LocalBroadcastManager example
package com.kinpo.android_test;
import android.app.Activity;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
@mr5z
mr5z / test.java
Last active December 22, 2015 05:51
Adding elements dynamically to MultiSelectListPreference
((EditTextPreference) findPreference("pref_scanning_editdialog"))
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
String value = newValue.toString();
if ( !value.isEmpty() ) {
// This doesn't seem right
CharSequence[] entries = list.getEntryValues();
ArrayList<CharSequence> entryList = new ArrayList<>(Arrays.asList(entries));
entryList.add(value);
@mr5z
mr5z / CommandProcessor.java
Created February 2, 2016 09:00
command queue polling service
package com.kinpo.bcutility;
import java.util.LinkedList;
import java.util.concurrent.TimeUnit;
import com.kinpo.bcutility.settings.Settings.CommandBehavior;
import com.kinpo.training.lazyutils.Debug;
public class CommandProcessor implements Runnable {
@mr5z
mr5z / PagerViewController.m
Created February 18, 2016 08:44
UIScrollView as a page container and UIViewController as pages
- (void)viewDidLoad {
[super viewDidLoad];
int pageCount = 2;
// int pageWidth = self.view.frame.size.width;
// int pageHeight = self.view.frame.size.height;
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
for(int i = 0;i < pageCount; ++i) {
UIViewController *page = [storyBoard
instantiateViewControllerWithIdentifier:
@mr5z
mr5z / somefile.m
Created February 20, 2016 09:26
#define is not an assignment operation
NSArray *APPLIANCES_ARRAY = @[@"Fridge",@"Microwave",@"PS3/PS4/XBOX"];
for(id appliance_group in APPLIANCES_ARRAY) {
NSLog(@"%@", appliance_group);
}
@mr5z
mr5z / a.m
Created April 14, 2016 01:45
Objective-C sucks!
@property (atomic, setter=setRunning:, getter=mIsRunning) BOOL mIsRunning;
@property (strong, nonatomic) FifoQueue *queue;
@end
@implementation BcxCommandQueueService
@synthesize mIsRunning;
#pragma mark - GETTERS
@mr5z
mr5z / database.m
Created May 13, 2016 02:15
query database asynchornously
- (void)query:(NSString *)query completion:(CompletionCallback)completion {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^ {
while(isBusy) {
// wait for it
// or should I say, sleep?
}
isBusy = YES;
@mr5z
mr5z / gist:62a9c8525afd2dabd329f8ad820415f8
Last active May 16, 2016 09:23
Get first day of the current week as NSDate
- (void)test_printDateVariants {
NSDateFormatter *fmt = [NSDateFormatter new];
NSTimeZone *timezone = [NSTimeZone timeZoneWithName:@"UTC"];
[fmt setTimeZone:timezone];
[fmt setDateFormat:@"yyyy-MM-dd hh:mm:ss Z"];
NSCalendar *calendar = [NSCalendar currentCalendar];
for(int i = 1;i <= 31; ++i) {
SELECT u.firstName AS sender FROM users u
INNER JOIN messages m
ON m.senderId = u.id
WHERE m.status = 'pending'
AND m.recipientId = $userId
-- GROUP BY u.id
@mr5z
mr5z / chat.php
Last active November 17, 2016 09:57
<?php
function updateUsersStatus() {
global $db;
$sql = "UPDATE users SET users.active = false WHERE users.lastSeenActive = NOW() - INTERVAL 10 SECOND";
$result = $db->query($sql);
if ($result) {
// we don't care about the result
}
else {