Skip to content

Instantly share code, notes, and snippets.

View soapyigu's full-sized avatar
🎯
Focusing

Soap soapyigu

🎯
Focusing
  • Netflix
  • San Francisco
View GitHub Profile
@interface Queue<ObjectType> : NSObject
- (void)enqueue:(ObjectType)value;
- (ObjectType)dequeue;
@end
@interface Queue()
@property (nonatomic, strong) NSMutableArray<id> *array;
@end
@implementation Queue
- (instancetype)init {
self = [super init];
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
NotificationCenter.default.addObserver(self, selector: Selector(("volumeDidChange:")), name: NSNotification.Name(rawValue: "AVSystemController_SystemVolumeDidChangeNotification"), object: nil)
return true
}
func volumeDidChange(notification: NSNotification) {
let volume = notification.userInfo!["AVSystemController_AudioVolumeNotificationParameter"] as! Float
// Volume at your service
import UIKit
import MediaPlayer
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let volumeView = MPVolumeView(frame: CGRect(x: 100, y: 100, width: 100, height: 100))
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let webView = UIWebView(frame: view.bounds)
view.addSubview(webView)
if let filePath = Bundle.main.path(forResource: "hack", ofType: "html") {
<!DOCTYPE html>
<html>
<body>
<script>
var localfile = "/etc/passwd"
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
alert(xhr.responseText);
}
TAGS="TODO:|FIXME:|WARNING:"
ERRORTAG="ERROR:"
find "${SRCROOT}" \( -name "*.h" -or -name "*.m" -or -name "*.swift" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($TAGS).*\$|($ERRORTAG).*\$" | perl -p -e "s/($TAGS)/ warning: \$1/"| perl -p -e "s/($ERRORTAG)/ error: \$1/"
extension Dictionary : Encodable /* where Key : Encodable, Value : Encodable */ {
public func encode(to encoder: Encoder) throws {
assertTypeIsEncodable(Key.self, in: type(of: self))
assertTypeIsEncodable(Value.self, in: type(of: self))
if Key.self == String.self {
// Since the keys are already Strings, we can use them as keys directly.
var container = encoder.container(keyedBy: _DictionaryCodingKey.self)
for (key, value) in self {
let codingKey = _DictionaryCodingKey(stringValue: key as! String)!
let dict: [Float : String] = [
18.0: "ff0000",
20.0: "00ff00",
21.0: "0000ff"
]
let encoder = JSONEncoder()
encoder.outputFormatting = [.prettyPrinted, .sortedKeys]
let encoded = try! encoder.encode(dict)
let jsonText = String(decoding: encoded, as: UTF8.self)
class Node {
var val: (Int, Int)
var next: Node?
init(_ val: (Int, Int)) {
self.val = val
}
}
class LinkedList {