Skip to content

Instantly share code, notes, and snippets.

View bouchtaoui-dev's full-sized avatar

Nordin-010 bouchtaoui-dev

  • Netherlands, Rotterdam
View GitHub Profile
@interface Box:NSObject
{
//Instance variables
double length; // Length of a box
double breadth; // Breadth of a box
}
@property(nonatomic, readwrite) double height; // Property
@end
// This one I use very often
dispatch_async(dispatch_get_main_queue(), ^{
// run following code in main queue
// this block will be put in the queue to be executed later
});
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// do some task in background
dispatch_async(dispatch_get_main_queue(), ^{
// update some UI
@interface Singleton : NSObject
@end
@implementation Singleton
+ (instancetype)sharedInstance {
static Singleton *sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name:

@bouchtaoui-dev
bouchtaoui-dev / SimpleSortArray.m
Created September 22, 2017 09:44
Ordering NSMutableArray by NSNumber
// source: https://stackoverflow.com/a/3207959/1012775
NSSortDescriptor *highestToLowest = [NSSortDescriptor sortDescriptorWithKey:@"self" ascending:NO];
[mutableArrayOfNumbers sortUsingDescriptors:[NSArray arrayWithObject:highestToLowest]];
- (void) notifyMessage: (NSString*) sender withMessage: (NSString*) message {
// source: http://useyourloaf.com/blog/local-notifications-with-ios-10/
NSLog(@"BackgroundServerice: Send a notification!");
message = message?message:@"";
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
// Create a content
UNMutableNotificationContent *content = [UNMutableNotificationContent new];
content.title = sender;
content.body = [ NSString stringWithCString:[ message cStringUsingEncoding:NSUTF8StringEncoding ]
@bouchtaoui-dev
bouchtaoui-dev / RVObserver.java
Created March 8, 2017 14:11 — forked from IshankGulati/RVObserver.java
Base Adapter and RecyclerView.ViewHolder implementation for delegating clicks to Fragment to which adapter is attached. This gist is inspired from https://gist.github.com/aurae/ebf8ec212e4296aebb24 .
/**
* Created by Ishank Gulati on 14/10/16.
* Observer as per Observer design pattern.
*/
public interface RVObserver {
void update(RecyclerViewItemClickListener listener);
}
@bouchtaoui-dev
bouchtaoui-dev / Example.java
Created March 7, 2017 14:53 — forked from nightscape/Example.java
Simple RxJava-based adapter for an Android RecyclerView
public class ReactiveTextViewHolder<T> extends ReactiveViewHolder<T> {
private TextView label;
private T currentItem;
public ReactiveTextViewHolder(View itemView) {
super(itemView);
label = (TextView) itemView.findViewById(android.R.id.text1);
}
@bouchtaoui-dev
bouchtaoui-dev / BaseAdapter.java
Created March 7, 2017 14:36 — forked from mannodermaus/BaseAdapter.java
RecyclerView.ViewHolder and Adapter demonstration
public abstract class BaseAdapter<T, VH extends BaseViewHolder<T>> extends RecyclerView.Adapter<VH> {
private List<T> items;
// Missing: setItems(), addItem(), removeItem(), ...
@Override
public final void onBindViewHolder(VH vh, int position) {
T item = items.get(position);
vh.performBind(item, position);
@bouchtaoui-dev
bouchtaoui-dev / BaseAdapter.java
Created March 7, 2017 14:36 — forked from mannodermaus/BaseAdapter.java
RecyclerView.ViewHolder and Adapter demonstration
public abstract class BaseAdapter<T, VH extends BaseViewHolder<T>> extends RecyclerView.Adapter<VH> {
private List<T> items;
// Missing: setItems(), addItem(), removeItem(), ...
@Override
public final void onBindViewHolder(VH vh, int position) {
T item = items.get(position);
vh.performBind(item, position);