Skip to content

Instantly share code, notes, and snippets.

@M-Medhat
M-Medhat / oauth2_password.rb
Created September 20, 2016 20:31 — forked from kuraga/oauth2_password.rb
Omniauth OAuth2 Password strategy
require 'oauth2'
require 'omniauth'
require 'securerandom'
require 'socket' # for SocketError
require 'timeout' # for Timeout::Error
require 'faraday' # for Faraday::Error::TimeoutError and Faraday::Error::ConnectionFailed
require 'multi_json' # for MultiJson::DecodeError
module OmniAuth
module Strategies
@M-Medhat
M-Medhat / PlaygroundResource.swift
Created February 2, 2015 09:37
Using resources in a Swift Playground
var error:NSError? = nil
if let mdStr = String(contentsOfFile: "/path/to/file/test.txt", encoding: NSUTF8StringEncoding, error: &error) {
print("File Opened!")
} else {
if(error != nil) {
print(error?.description)
}
}
@M-Medhat
M-Medhat / RegExReplace.swift
Created February 2, 2015 09:33
Regular Expressions: How to replace patterns in Swift
// You need to import Foundation to use NSRegularExpression, NSError and NSString
import Foundation
/// This function takes three parameters
/// text: a string that we search in
/// pattern: a reqular expression pattern to use in the search
/// withTemplate: the string that we use instead of the occurrances we find in text
///
/// The method returns (text) with occurrance found using (pattern) replaced with (withTemplate)
func regexReplace(text:String, pattern:String, withTemplate:String) -> String {
@M-Medhat
M-Medhat / full-width-image.css
Created February 2, 2015 09:03
Full width images
img {
max-width: 100%;
max-height: 100%;
}