Skip to content

Instantly share code, notes, and snippets.

View ymoussaba's full-sized avatar
:shipit:

Yann Moussaba ymoussaba

:shipit:
View GitHub Profile
@ymoussaba
ymoussaba / store.test.dart
Last active November 17, 2020 01:33
Mobx Store Test
class MockOrderRepository extends Mock implements IRepository<Order> {}
void main() {
final mockOrderRepository = MockOrderRepository();
final item = OrderItem(
quantity: 1,
id: "klm",
price: 5,
vat: 0,
@ymoussaba
ymoussaba / localhost-ssl-certificate.md
Created September 13, 2020 23:58 — forked from ethicka/localhost-ssl-certificate.md
Localhost SSL Certificate on Mac OS Sierra and High Sierra

This gives you that beautiful green lock in Chrome. I'm assuming you're putting your SSL documents in /etc/ssl, but you can put them anywhere and replace the references in the following commands. Tested successfully on Mac OS Sierra and High Sierra.

Set up localhost.conf

sudo nano /etc/ssl/localhost/localhost.conf

Content:

[req]
main() {
final state = LoginState.Initial;
print(state.value);
}
class LoginResponse {}
class Error {}
class LoginState {
@ymoussaba
ymoussaba / rotate.js
Created September 2, 2019 15:48 — forked from rumblestrut/rotate.js
Rotating images with javascript
Oh sure, you could do this with jQuery, but in my early days, this is what I used ...
<script>
<!--
// Set slideShowSpeed (milliseconds)
var slideShowSpeed = 8000
// Duration of crossfade (seconds)
var crossFadeDuration = 3
@ymoussaba
ymoussaba / README.md
Created September 18, 2018 00:24 — forked from erichrobinson/README.md
SwitchResX Configuration

#SwitchResX Settings for LG 21:9 UltraWide

SwitchResX is a utility that allows users to override the default resolution settings in OSX. For more information, including download links, vist http://www.madrau.com/ .

##Disabling System Integrity Protection (SIP)

If you are running OSX 10.11 or higher, SIP must be disabled. To disable SIP do the following:

  • Boot into the recovery partition by pressing CMD + R when starting up your Mac.
  • Once in recovery mode, open a terminal window.
  • Type the command csrutil disable
@ymoussaba
ymoussaba / firebase_player_assignment.js
Created December 6, 2017 23:08 — forked from anantn/firebase_player_assignment.js
Firebase: Assigning players in a multiplayer game. This snippet assigns you a spot in a game if the game isn't full yet.
function go() {
var userId = prompt('Username?', 'Guest');
// Consider adding '/<unique id>' if you have multiple games.
var gameRef = new Firebase(GAME_LOCATION);
assignPlayerNumberAndPlayGame(userId, gameRef);
};
// The maximum number of players. If there are already
// NUM_PLAYERS assigned, users won't be able to join the game.
var NUM_PLAYERS = 4;
@ymoussaba
ymoussaba / timeago.swift
Created May 7, 2017 14:27 — forked from minorbug/timeago.swift
"Time ago" function for Swift (based on MatthewYork's DateTools for Objective-C)
func timeAgoSinceDate(date:NSDate, numericDates:Bool) -> String {
let calendar = NSCalendar.currentCalendar()
let unitFlags = NSCalendarUnit.CalendarUnitMinute | NSCalendarUnit.CalendarUnitHour | NSCalendarUnit.CalendarUnitDay | NSCalendarUnit.CalendarUnitWeekOfYear | NSCalendarUnit.CalendarUnitMonth | NSCalendarUnit.CalendarUnitYear | NSCalendarUnit.CalendarUnitSecond
let now = NSDate()
let earliest = now.earlierDate(date)
let latest = (earliest == now) ? date : now
let components:NSDateComponents = calendar.components(unitFlags, fromDate: earliest, toDate: latest, options: nil)
if (components.year >= 2) {
return "\(components.year) years ago"
@ymoussaba
ymoussaba / Alamofire-JSON-Serialization.md
Created April 7, 2016 19:49 — forked from jpotts18/Alamofire-JSON-Serialization.md
Alamofire JSON Serialization of Objects, Collections, Nesting

Alamofire JSON Serialization of Objects and Collections

Alamofire is a great Swift library developed by the creator of AFNetworking @mattt. The purpose of this gist is to explain how to use the built-in power of Alamofire to serialize your JSON. In this example we will be serializing a simple blog API. First we will start with serializing a single JSON object and add complexity as we go along.

Warning: This was written before Swift 1.2

A Single JSON Serialization

This is the first JSON object that we will be serializing.

@ymoussaba
ymoussaba / Image.m
Created February 27, 2016 23:09
iOS: How to retrieve image dimensions without loading CGImage into memory
// This method requires ImageIO.framework
#import <ImageIO/ImageIO.h>
- (CGSize)sizeOfImageAtURL:(NSURL *)imageURL
{
// With CGImageSource we avoid loading the whole image into memory
CGSize imageSize = CGSizeZero;
CGImageSourceRef source = CGImageSourceCreateWithURL((CFURLRef)imageURL, NULL);
if (source) {
NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:(NSString *)kCGImageSourceShouldCache];