Skip to content

Instantly share code, notes, and snippets.

View lseongjoo's full-sized avatar

Lee Seongjoo lseongjoo

  • CodeBasic
  • Seoul, Korea
View GitHub Profile
@lseongjoo
lseongjoo / console_arg_to_unicode.py
Created August 18, 2015 09:41
콘솔의 인코딩 정보를 활용해 명령줄 인자를 유니코드로 변환하기
# coding: utf-8
# @LeeSeongjoo
import sys
if __name__ == '__main__':
# 명령줄 인자를 유니코드로 변환
uargv = [arg.decode(sys.stdin.encoding) for arg in sys.argv[1:]]
print(uargv)
@lseongjoo
lseongjoo / bigpy-2015-07-19.py
Last active August 29, 2015 14:25
웹 API 요청 질문 관련 (2015-07-19)
# coding: utf-8
"""
https://www.facebook.com/bigpython
"""
import requests
response = requests.get('http://api.openhangul.com/dic', {'api_key':20141107174448, 'q':u'좋다'})
# content-length
cLen = response.headers['Content-Length']
# Get the content of the HTTP response
@lseongjoo
lseongjoo / ndarray_instead_for.py
Last active August 29, 2015 14:25
반복문 대신 NumPy 배열 사용
import random
import numpy as np
def gen_sim_pure_python():
"""Pure Python"""
prices = [[np.random.randint(5,1000)] for i in range(10)]
changes = [[np.random.uniform(-0.3, 0.3) for i in range(90)] for i in range(10)]
for p, c in zip(prices, changes):
for delta in c:
p.append(p[-1]*(1+delta))
@Override
public void onTextChanged(CharSequence s, int start, int before, int count){
if(start >0 && before == 1 && count == 1){
if(geocoderTask != null){
gecoderTask.cancel(true);
}
geocodeTask = new GeocodeTask();
}
}
import urllib
import BeautifulSoup
data = urllib.urlopen('http://www.fdic.gov/bank/individual/failed/banklist.html')
soup = BeautifulSoup.BeautifulSoup(data)
banklist = soup.find('table', attrs={'class', 'sortable'})
@lseongjoo
lseongjoo / graph.py
Last active December 13, 2015 16:49
A simple graph data structure
#!/usr/bin/env python
import itertools
class Graph(dict):
def __init__(self, vs=[], es=[]):
"""create a new graph. (vs) is a list of vertices;
(es) is a list of edges."""
for v in vs:
self.add_vertex(v)
public class MainActivity extends android.support.v4.app.FragmentActivity {
// Only one MapView instance is allowed per MapActivity,
// so we inflate it in the MainActivity and tie its
// lifetime here to the MainActivity. Package scope
// so we can grab them from different instances of map
// fragments.
//
// The other option was to make them static, but that causes
// memory leaks on screen rotation.
View mMapViewContainer;
// ERROR!
void printArray(int arr[][])
{
for(int i=0; i<2; i++)
for(int j=0; j<3; j++)
cout << a[i][j] << " ";
cout << endl;
}
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
public class TimeUtil {
public static Timestamp getTimestamp(){
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
return timestamp;
}
int i;
for(i=1; i<=10; i++);
{
std::cout << i << " ";
}