Skip to content

Instantly share code, notes, and snippets.

View e-sung's full-sized avatar

류성두 e-sung

View GitHub Profile
@e-sung
e-sung / downloadFile.swift
Created January 18, 2018 05:25
download File From Web with Alamofire
func downloadFile(from remoteURL: URL, completion: @escaping (_ localURL: URL) -> Void) {
let documentsDirectoryURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
let destinationUrl = documentsDirectoryURL.appendingPathComponent(randomString)
if FileManager.default.fileExists(atPath: destinationUrl.path) {
DispatchQueue.main.async { completion(destinationUrl) }; return
}
URLSession.shared.downloadTask(with: remoteURL, completionHandler: { (location, response, error) -> Void in
guard let location = location, error == nil else { return }
do {
@e-sung
e-sung / bigEnter.js
Created April 29, 2018 06:15
Make Enter Key to Simulate Mouse click
var cursorX = 0
var cursorY = 0
document.onmousemove = function(e){
cursorX = e.pageX;
cursorY = e.pageY;
}
document.addEventListener('keypress', function (e) {
var key = e.which || e.keyCode;
@e-sung
e-sung / todayCommit.sh
Last active February 27, 2020 13:48
Shell Script that Generates List of Git Commit Messages of All branches on a given day
#! /usr/local/bin/zsh
authorName="Sungdoo Yoo" #Put your Name here
dayStart="8am" #Put the time when you start your day
for refName in $(git for-each-ref --format='%(refname)' refs/heads/);
do
boilerPlateToRemove="refs/heads/"
branchName="${refName//$boilerPlateToRemove/""}"
result=""
@e-sung
e-sung / generateChangelog.sh
Created December 10, 2018 01:10
Generate Changelog between Two branches
#! /bin/bash
# Generate Log with commits with certain prefixes ( `-`, `*`, `.`)
git log $1...$2 --no-merges --format="%Cgreen## %s%n%Creset%b" --grep "- " --grep "\. " --grep "\* " >> changelog.md
let dateFormat = DateFormatter()
dateFormat.dateFormat = "yyyy/MM/dd/HH/mm/ss"
print(dateFormat.date(from: "20160610090000"))
let dateFormat = DateFormatter()
dateFormat.dateFormat = "yyyy/MM/dd/HH/mm/ss"
dateFormatter.locale = Locale(identifier:"en_US_POSIX") // 추가 된 코드
print(dateFormat.date(from: "20160610090000"))
@e-sung
e-sung / badway.swift
Created May 9, 2019 14:11
Bad way of using UITableViewDataSource
class ModelController: NSObject {
var kittisList = ["🐱", "😹", "😼", "😸", "😽", "😾"]
var smileyList = ["😐", "😂", "😏", "😊", "😊", "😠", "😱"]
}
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
// MARK: - View
@IBOutlet var tableView: UITableView!
@IBOutlet var segmentControl: UISegmentedControl!
@e-sung
e-sung / betterViewController.swift
Last active May 9, 2019 14:48
better viewcontroller with seperate datasource
class ViewController: UIViewController {
// MARK: - View
@IBOutlet var tableView: UITableView!
@IBOutlet var segmentControl: UISegmentedControl!
// MARK: - DatSources
var dataSources:[UITableViewDataSource] = []
let catDataSource = CatDataSource()
let smileyDataSOurce = SmileyDataSource()
// 옛날 버전. "세그먼트 콘트롤이 눌리면 테이블뷰를 리로드하라"로 밖에 읽히지 않는다.
@IBAction func segementSelected(_ sender: UISegmentedControl) {
tableView.reloadData()
}
// 리팩토링버전. "선택된 세그먼트에 해당되는 데이터로 테이블을 채워라"라는 의도가 보인다.
@IBAction func segementSelected(_ sender: UISegmentedControl) {
tableView.dataSource = dataSources[sender.selectedSegmentIndex]
tableView.reloadData()
}
class SmileyDataSource: NSObject, UITableViewDataSource {
var dataList: [String] = []
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return dataList.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let item = dataList[indexPath.row]
let cell = tableView.dequeueReusableCell(withIdentifier: "smileyCell", for: indexPath)
cell.textLabel?.text = item