Skip to content

Instantly share code, notes, and snippets.

View devxoul's full-sized avatar
👨‍💻
Always coding

Jeon Suyeol devxoul

👨‍💻
Always coding
View GitHub Profile
extension ObservableType {
typealias Accumulator<A> = (A, E) -> Observable<A>
func flatScan<A>(_ seed: A, accumulator: @escaping Accumulator<A>) -> Observable<A> {
return self
.scan(Observable<A>.just(seed)) { observable, current -> Observable<A> in
observable.flatMap { previous in
accumulator(previous, current)
}
}
@devxoul
devxoul / ios10-url-open-location-service.swift
Created February 14, 2017 10:02
Open Settings > Privacy > Location Service in iOS 10
// Example Usage
func openLocation() {
guard let workspaceClass = NSClassFromString("LSApplicationWorkspace") else { return }
let workspace: AnyObject = execute(workspaceClass, "defaultWorkspace")
let url = URL(string: "Prefs:root=Privacy&path=LOCATION")!
execute(workspace, "openSensitiveURL:withOptions:", with: url)
}
private func getImplementation(_ owner: AnyObject, _ name: String) -> IMP {
let selector = Selector(name)
@devxoul
devxoul / seoulpokemap-iv-filter.js
Last active February 3, 2021 03:14
IV filter for seoulpokemap.com
function filteredPokemonsByIV(pokemons, iv) {
iv = iv || 0.9;
return pokemons.filter(function (pokemon) {
var currentIV = (pokemon.attack + pokemon.defence + pokemon.stamina) / 45;
return currentIV >= iv;
});
}
function arePokemonsEqual(lhs, rhs) {
if (lhs.length != rhs.length) {
@devxoul
devxoul / README.md
Last active November 21, 2016 08:54
List slow compile functions in Swift

Slow.py

Usage

$ xcodebuild clean build -workspace 'MyApp.xcworkspace' -scheme 'MyApp' OTHERFLAGS="-Xfrontend -debug-time-function-bodies" | tee xcode_raw.log
$ python slow.py xcode_raw.log
23559.6ms   ./Sources/A.swift:219:16    @objc dynamic func doneButtonDidTap()
23439.6ms ./Sources/B.swift:763:8 @objc final func checkCondition()
@devxoul
devxoul / Array+ing.swift
Created October 5, 2016 12:10
Arraying
// The MIT License (MIT)
//
// Copyright (c) 2016 Suyeol Jeon (xoul.kr)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
extension UICollectionView {
public var rx_reachedBottom: Observable<Void> {
return self.rx.contentOffset
.map { contentOffset in
var responder: UIResponder = self
var viewController: UIViewController? = nil
while let next = responder.next {
viewController = next as? UIViewController
if viewController != nil {
@devxoul
devxoul / ga-os-version-sub.js
Created September 26, 2016 17:09
Google Analytics OS 버전 합계(%) 구하기
(function() {
var VERSION = '8'
var total = 0;
$('#ID-explorer-table-pieTable tr')
.each(function(i, tr) {
var version = $(tr).find('td:nth-child(3)').text();
if (version.startsWith(VERSION)) {
var percentString = $(tr).find('td:nth-child(5)').text();
var percent = Number(percentString.split('%')[0]);
total += percent;
@devxoul
devxoul / ObservableConvertibleType+ActivityIndicator.swift
Last active July 29, 2016 14:33
RxSwift: Filters the elements of an observable sequence based on an ActivityIndicator.
// The MIT License (MIT)
//
// Copyright (c) 2016 Suyeol Jeon (xoul.kr)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
@devxoul
devxoul / SR-1117.swift
Last active March 31, 2016 09:49
Overridden function is not being called when sublassing generic class in Release Build with Whole Module Optimization. https://bugs.swift.org/browse/SR-1117
/// A generic class
class Parent<T> {
func printName() {
print(self.name())
}
func name() -> String {
return "Parent"
}
@devxoul
devxoul / phone_number_formatter.php
Last active December 15, 2015 17:16
Phone number formatter for Korean.
<?php
function phone($str) {
$AREA_CODES = array("010", "02", "011", "031", "012", "032", "033", "041",
"015", "042", "016", "043", "017", "044", "018", "051",
"019", "052", "053", "054", "055", "061", "062", "063",
"064");
// 하이픈 모두 제거
$flattened = str_replace("-", "", $str);