Skip to content

Instantly share code, notes, and snippets.

sooop

Block or report user

Report or block sooop

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View IntListParser.hs
import Data.Char (isDigit, isSpace)
newtype Parser a = Parser { runParser :: String -> [(a, String)]}
instance Functor Parser where
fmap f p = Parser $ \str ->
case runParser p str of
[] -> []
[(y, ys)] -> [(f y, ys)]
@sooop
sooop / example.py
Created Jun 16, 2019
비동기 PUSH-PULL 분산처리 구조 - onefile
View example.py
from multiprocessing import Process
import sys
import random
import zmq
import zmq.asyncio
import asyncio
ctx = zmq.asyncio.Context()
View publisher.py
import sys
import random
import asyncio
import zmq
import zmq.asyncio
ctx = zmq.asyncio.Context()
async def run_server(port=5556):
sock = ctx.socket(zmq.PUB)
@sooop
sooop / e001.jl
Last active Jan 10, 2019
Project Euler with Julia 001-010
View e001.jl
@elapsed sum(i for i=1:999 if i % 3 == 0 || i % 5 == 0) |> println
## FASTER SOLUTION
@time (Set(3:3:999) ∪ Set(5:5:999)) |> sum |> println
@sooop
sooop / reversed_lines.py
Created Jul 20, 2018
Read a file line by line in reversed order (lazily) in python3
View reversed_lines.py
def reversed_lines(filepath, sep='\n'):
token = sep.encode()
buffer = bytearray()
chunk_size = 1024
c = 0
with open(filepath, 'rb') as f:
total_bytes = f.seek(0,2)
# 버퍼에 한 번을 읽어들인다.
while True:
c += 1
@sooop
sooop / prime.py
Created May 10, 2018
소수 판별함수
View prime.py
def is_prime(n: int) -> bool:
if n < 2: return False
if n < 4: return True
if n % 2 == 0 or n % 3 == 0:
return False
if n < 9: return True
k, l = 5, n ** 0.5
while k <= l:
if n % k == 0 or n % (k+2) == 0:
return False
@sooop
sooop / main.swift
Last active Jan 30, 2018
문자열의 편집거리 구하기
View main.swift
private extension String {
subscript(i:Int) -> Character {
let idx = index(startIndex, offsetBy: i)
return self[idx]
}
}
struct Array2D<T> {
let width: Int, height: Int
@sooop
sooop / property-sample.swift
Created Jan 22, 2018
Swift 클래스의 프로퍼티와 상속 예제
View property-sample.swift
//: Playground - noun: a place where people can play
//: ## 1 : 클래스의 프로퍼티 정의방법
class Foo {
/// 일반적인 stored property
var a: Int = 4
/// stored property + observer methods
var b: Int = 10 {
willSet {
@sooop
sooop / to_many_kvo.swift
Last active Jan 10, 2018
to-many relationship에 대한 KVO 처리방법
View to_many_kvo.swift
import Foundation
// MARK: Employee
class Employee: NSObject
{
@objc dynamic var salary:Int
var name: String
init(name:String, salary:Int) {
self.name = name
@sooop
sooop / main.m
Created Jan 9, 2018
Basic KVC/KVO Implementation
View main.m
#import <Foundation/Foundation.h>
static void* theContext = &theContext;
/// KVC/KVO 호환 클래스.
@interface Foo: NSObject
@property (copy, nonatomic) NSString* moo;
-(void)doubleBar;
@end
You can’t perform that action at this time.