| 일반적으로 웹사이트 작업을 하다보면 노이미지 처리가 필요한경우가 있습니다. 쇼핑몰을 예를 들면 해당 이미지가 없거나 하는경우의 처리인데요 이게 몇개 정도면 문제가 없지만 많을경우 성능에 심각한 영향을 줍니다. 하지만 자바스크립트로 오류를 체크할수 있는데 jQuery로 하면 매우 간단합니다. 다음을 보시면 $(function() {
$('img').error(function() {
alert('before');
$(this).attr('src', 'no-image.png');
});
});이미지가 오류가 있는경우 no-image.png로 대체하라 입니다. 머 텍스트등으로 대체할수도 있구요 그경우 $(this).replaceWith('으로 처리할수 있습니다. 한방에 처리할수있으니 편리하죠 ^_^ |
'2010/02'에 해당되는 글 14건
- 2010/02/17 jQuery로 노이미지 처리하기
- 2010/02/16 WTFJS
- 2010/02/11 groovyConsole 의 활용
- 2010/02/11 구글 버즈의 등장!
- 2010/02/10 Faye Bayeaux 프로토콜 Node.js를 위한 서버 혜성 프로토콜 ( Faye: Bayeaux protocol Comet server for Node.js )
- 2010/02/10 당신은 자바스크립트를 안다고 생각하십니까? 퀴즈를 풀어보세요! ( Think You Know Javascript? Try this Quiz! )
- 2010/02/10 자바스크립트 EPub 리더기 ( Javascript ePub Readers )
- 2010/02/06 크롬을 지원하는 그리스몽키와 함께 사용자 스크립트가 가능하게 된다 (User scripts becoming more portable with Greasemonkey support in Chrome)
- 2010/02/05 SVG-Edit의 새로운 버전 ( New Version of SVG-Edit )
- 2010/02/05 PHP 코드 최적화 40가지팁(번역)
Posted on 2010/02/17 15:08
Filed Under Development/AJAX
Posted on 2010/02/16 14:27
Filed Under Development/Ajaxian
The title need no more flushing out. Brian Leroux has created WTFJS to capture some of the rough edges of JavaScript. The stuff that made Crocky write about the Good Parts. Brian Leroux Tlsms 씨는 자바스크립트의 거친 가장자리의 한부분을 캡쳐하여 보여주기의해 WTFJS라는 사이트를 만들었습니다. 자바스크립트의 문제점에 대하여 썼습니다. Fun side effects such as: JAVASCRIPT:
Got a fun one? Add it to the site! 재미있는것을 가지고 있나요? 이사이트에 추가해주세요 |
Posted on 2010/02/11 17:35
Filed Under Development/groovy
보통 스크립팅언어들은 함께 설치되는 스크립트 에디터가 있습니다. 해당 스크립트로 작성된 에디터인데 역시 그루비에도 있습니다! ![]() 해서 이번에 groovyConsole을 이용해서 간단한 테스트 등을 수행해보도록 하죠 일단 groovyConsole을 실행하면 다음과 같은 화면이 뜹니다. ![]() 보통 개발일을 하다면 간단한 수식이나 테스트들이 필요한 경우가 있는데요 그런일에는 딱입니다. 보통 IDE는 간단한 작업하는데도 프로젝트 만들고 어쩌고 해야하고 또 기존 프로젝트에다가 지저분하게 추가해야되는 부분들이 있는데 그런것들을 해소해주는데는 적격이라고 생각됩니다. 자 간단한 계속을 해봅시다~ 실행은 Ctrl + R 혹은 Ctrl + Enter 입니다. (Ctrl + Enter 하니까 예전에 플래시 작업이생각나네요) 1 + 1 결과 : Result: 2 바로 계속 결과가 나오는데요. 여기서 아셔야할점이 groovy에서는 가장 마지막 수행된 결과가 리턴됩니다. 고로 다음을 수행하면
결과 : Result: 4 이런결과가 나옵니다. 물론 return 으로 해줘도 동작합니다. 물론 둘다의 결과를 모두 출력하려면 println 1 + 1 println 2 + 2 식으로 명시적으로 출력문을 적어주면 됩니다. 자 이제 어떤것이 가능할까요~ 간단한 제곱함수를 테스팅해보겠습니다.
결과 :
times라는 건 '몇번 실행해라' 입니다. 10.times는 10번 수행하라이고 안에 it는 증가되는 인덱스입니다. 또 다음과 같은것도 가능합니다. 당연히 자바에서 수행가능한 모든것들이 가능하지요~
![]() Hello Groovy! 경고창을 띄우는 예제입니다. SWT도 물론 가능합니다. 다음 링크에서 확인할수 있는데요 하지만 해당 라이브러리를 추가해주어야 합니다. Script > Add Jar to Classpath 나 Script > Add Directory to Classpath를 해서 해당 라이브러리를 추가해주는 어떤것도 실행가능합니다. 정말 빠르게 발전하고 있는 그루비. 하루빨리 일반적으로 사용하게 되길 빕니다 후후 |
Posted on 2010/02/11 17:34
Filed Under 컴퓨터 일반
| 버즈질에 푹 빠져있습니다. 여러분도 함께해요~ 저를 추가해주세요~ takesoft@gmail.com |
Posted on 2010/02/10 09:52
Filed Under Development/Ajaxian
On the client side: 클라이언트 코드 HTML: JAVASCRIPT:
And the backend.... 그리고 백엔드단 JAVASCRIPT:
Nice! 좋았어 |
Posted on 2010/02/10 09:43
Filed Under Development/Ajaxian
There are fourteen questions in all, starting here: 여기 모든 14개의 문제가 있다. 여기서 시작하라: takeone : 달랑 두개 맞았습니다. 무지 어렵고 헷갈리네요 ; |
Posted on 2010/02/10 09:37
Filed Under Development/Ajaxian
eBooks have gone mainstream, and right now the open ePub format is getting a lot of attention, being the iPad's book format of choice. Often overlooked in gadget-centric media is the fact that ePub is based on web standards, and therefore amenable to being rendered in the browser, sans plugins. Pure Javascript ePub readers are starting to crop up, and Keith Fahlgren has written about several of them: 이북은 주류를 가지고 있고 지금 오픈 ePub 포맷은 많은 주목을 받고 있으며 아이패드의 이북 포멧을 선택하고 있다. 종종 가잿중심의 미디어에서 간과되고 있는것은 ePub가 웹 표준에 기준되어 있고 따라서 snas 플러그인, 브라우저안에 랜더링 되야할 의무가 있다. 순수한 자바스크립트 ePub 리더기는 자르기를 시작하는것이다. 그리고 Keith Fahlgren 은 그들중 몇가지에 대해서 썼다:
All are open source, and as Keith notes in the comments, there's also the commercial BookGlutton project. BookGlutton (which we covered earlier) shows the promise of browser-based eBooks: it lets you embed books as lightbox-powered widgets, and supports annotation. 모든것은 오픈소스이고 Keith 노트 안의 코멘트는 그들이 또한 상업의 BookGlutton project이다. BookGlutton( 우리가 이전에 어떤 커버)는 브라우저 베이스의 eBook을 약속해주는것을 보여준다. 이것은 당신이 책을 lightbox-powered 위젯으로 포함하고 주석을 제공할것이다. The underlying structure of ePub is described on wikipedia: ePub의 기본구조는 위키피디아에 서술되어있다.
In the case of unzipping, Keith points out the inflate library has been around since 1999. One can imagine other applications for zip too; for example, it's often used as a format for bundling code (Java JARs, Python Eggs, Firefox and Chrome extensions), so reliable unzipping makes it possible to build browser-based IDEs and exploration tools against such archives. |
Posted on 2010/02/06 10:16
Filed Under Development/Ajaxian
Aaron Boodman created Greasemonkey back in the day. He also worked on Gears. And most recently he created Chrome Extensions. I have a funny feeling that folks were pinging him daily "hey, when ya gunna give me Greasemonkey on Chrome" and he just delivered: 아론 부드맨은 전에 그리스몽키를 만들었다. 그능 또한 기어스에서 일했다. 그리고 최근 그는 크롬 확장을 만들었다. 재미있게 느끼는것은 여러분이게 그가 메일 외치는것이다. "이봐 크롬 에서 그리즈 몽키를 나아게 줘라" 그리고 그능 배달했다. One thing that got lost in the commotion of the extensions launch is a feature that is near and dear to my heart: Google Chrome 4 now natively supports Greasemonkey user scripts. Greasemonkey is a Firefox extension I wrote in 2004 that allows developers to customize web pages using simple JavaScript and it was the inspiration for some important parts of our extension system. 구글 크롬 4는 사용자 그리즈 사용자 스크립트을 기본적으로 지원하게 되었다. 그리즈몽키는 파이어폭스 플러그인이다. 내가 2004에 웹페이지를 커스터마이징 할수 있게 개발자들을 따랐을때 간단한 자바스크립트와 이것에 영감을 었어 우리의 확장시스템의 일부로써 중요하다. Not all of the scripts will work. The deeper the integration, the less chance of success. We now have user scripts supported in a variety of browsers, and hopefully they get more and more portable. 모든 스크립트가 동작하진 않는다. 이것은 깊숙하게 통합되어있고 성공적으로 바꾼다. 우리는 다양한 브라우저의 사용자 스크립트를 지원하는것을 가지고 있다. 그리고 그것들이 머 많은것이 가능하도록 희망하고 있다. If browsers could surface the functionality to mainstream users, good things could happen beyond us power users. 만약 브라우져들이 주류 유져들의 기능저인 표면을 할수있다면 상품은 우리 파워유져들 뒤에 있을것이다. |
Posted on 2010/02/05 15:44
Filed Under Development/Ajaxian
SVG-Edit is a nifty open source editing web app that uses SVG and doesn't need a server-side: SVG-Edit 는 서버사이드를 필요로 하지않고 SVG를 이용하는 실용적인 오픈소스 에디팅 웹 어플리케이션이다.
The SVG-Edit team recently announced SVG-Edit 2.4, code named Arbelos. New features include: SVG-Edit 팀은 최근 SVG-Edit 2.4를 내놨다. 코드 네임은 Arbelos이다. 새로운 기능은 다음을 포함한다. - Raster Images - 바둑판식 이미지 Try out the demo here: 여기 데모가 있다. Check out the project page: 프로젝트 페이지를 체크하라 Read the release notes: 릴리즈 노트를 읽어라 |
Posted on 2010/02/05 15:38
Filed Under Development/PHP
가끔 PHP로 웹페이지를 작성할 일이 있는데, 유용한 팁을 우연히 보게 한글로 옮겨적어본다.원본은 40 Tips for optimizing your php Code 1. If a method be static, declare it static. Speed improvement is by a of 4. 메쏘드가 static이 될 수 있다면 static으로 선언하라. 4배 2. echo is faster than print. echo가 print보다 빠르다. 3. Use echo’s multiple parameters instead of string concatenation. 문자열을 말고, echo를 이용하여 여러 개의 파라미터를 적어라. 4. Set maxvalue for your for-loops before and not in the loop. 루프을 위핸 최대값(탈출조건)을 루프 안에서가 아니고 루프 시작 이전에 지정하라. 5. Unset your variables to free memory, especially large arrays. 해제하기 위해 변수를 unset하라. 특히 커다란 배열은 그래야 된다. Avoid magic like __get, __set, __autoload __get, __set, __autoload와 같은 피해라. 7. require_once() is expensive require_once()는 비싸다. 8. full paths in includes and requires, less time spent on the OS paths. include와 require를 사용할 때, 경로를 찾는데 시간이 걸리는 full path를 사용하라. 9. If you need find out the time when the script started executing, $_SERVER[’REQUEST_TIME’] preferred to time() 스크립트가 언제 실행했는지 알고 싶으면 time()보다 $_SERVER['REQUEST_TIME']이 10. See if you can use strncasecmp, strpbrk and instead of regex 정규표현식보다는 가능하면 strncasecmp나 strpbrk, stripos를 사용하라. * strncasecmp: 두 문자열의 앞쪽 일부가 대소문자 구분없이 일치하는지 확인할 때 strpbrk: 문자 집합에 속한 특정 문자가 문자열에 나타나는지 확인할 때 stripos: 대소문자 구분없이 특정 문자열이 다른 문자열에 포함되는지 확인할 때 11. str_replace is faster than preg_replace, but strtr is than str_replace by a factor of 4 str_replace가 preg_replace보다 빠르지만, str_replace보다 4배 빠르다. 12. If the function, such as replacement function, accepts both arrays and single characters as arguments, if your argument list is not too long, consider writing few redundant replacement statements, passing one character at a time, of one line of code that accepts arrays as search replace arguments. 만약 문자열 교체 같은 함수가 배열과 문자열을 인자로 그리고 그 인자 리스트가 길지 않다면, 배열을 한 번에 받아들여서 것 대신에 한 번에 문자열을 하나씩 넘겨서 처리하는 것을 고려해봐라. 13. It’s better to use select statements than multi else if, statements. 여러 개의 if/else if 문장 대신에 select 사용하는 게 더 좋다. 14. Error suppression with is very slow. @를 이용한 에러 출력 방지는 매우 느리다. 15. Turn on apache’s mod_deflate Apache의 mod_deflate를 켜라. *역주 mod_deflate는 출력을 클라이언트에게 보내기 전에 압축하는 모듈임 16. Close your connections when you’re done with them DB를 다 사용했으면 연결을 17. $row[’id’] is 7 times faster than $row[id] $row['id']가 7배 빠르다. 18. Error messages are expensive 에러 메시지는 19. Do not use functions inside of for loop, as for ($x=0; $x < count($array); $x) The count() function called each time. for 루프의 표현식 안에서 함수를 사용하지 마라. ($x = 0; $x < count($array); $x)에서 count() 함수가 매번 20. Incrementing a local variable in a method is fastest. Nearly the same as calling a local variable in function. 메쏘드 안에서 지역 변수를 증가시키는 것이 거의 함수 안에서 변수를 호출(증가?)하는 것만큼 빠르다. 21. Incrementing a global variable 2 times slow than a local var. 전역 변수를 증가시키는 지역 변수를 증가시키는 것보다 2배 느리다. 22. Incrementing an property (eg. $this->prop++) is 3 times slower than a local 객체의 멤버변수를 증가시키는 것이 지역 변수를 증가시키는 것보다 3배 느리다. 23. Incrementing an undefined local variable is 9-10 times slower a pre-initialized one. 값이 지정되지 않은 지역 변수를 증가시키는 것이 초기화된 변수를 증가시키는 것보다 9~10배 느리다. 24. Just declaring global variable without using it in a function also slows down (by about the same amount as incrementing a local PHP probably does a check to see if the global 전역 변수를 함수 안에서 사용하지 않으면서 그저 선언하기만 해도 (지역 증가시키는 것만큼) 느려진다. PHP는 아마 전역 변수가 존재하는지 알기 위해 하는 것 같다. 25. Method invocation appears to be of the number of methods defined in the class because added 10 more methods to the test class (before and the test method) with no change in performance. 메쏘드 호출은 안에서 정의된 메쏘드의 갯수에 독립적인 듯 하다. 왜냐하면 10개의 메쏘드를 클래스에 추가해봤으나 성능에 변화가 없었기 때문이다. 26. Methods in classes run faster than ones defined in the base class. 클래스의 메쏘드가 베이스 클래스에서 정의된 것보다 더 빠르게 동작한다. A function call with one parameter and an empty function takes about the same time as doing 7-8 $localvar++ operations. similar method call is of course about 15 $localvar++ operations. 개의 매개변수를 가지고 함수를 호출하고 함수 바디가 비어있다면(함수 내부에서 아무것도 않는다면) 그것은 7~8개의 지역변수를 증가시키는 것과 똑같은 시간을 차지한다. 비슷한 호출은 마찬가지로 15개의 지역변수를 증가시키는 연산쯤 된다. 28. Surrounding string by ‘ instead of ” will make things interpret little faster since php looks for variables inside “…” but inside ‘…’. Of course you can only do this when don’t need to have variables in the string. 문자열을 이중 대신에 단일 따옴표로 둘러싸는 것은 좀 더 빠르게 해석되도록 한다. PHP가 이중 따옴표 안의 변수를 찾아보지만 단일 따옴표 안에서는 변수를 않기 때문이다. 물론 문자열 안에서 변수를 가질 필요가 없을 때만 사용할 수 있다. 29. When echoing strings it’s faster separate them by comma instead of dot. Note: This only with echo, which is a function that can take several as arguments. 문자열을 echo할 때 마침표 대신에 쉼표로 분리하는 것이 빠르다. 주의: 이것은 여러 문자열을 인자로 받아들이는 함수인 echo로만 작동한다. 30. A PHP script will be served at least 2-10 times slower than a static HTML page by Apache. Try to use more static HTML pages and fewer scripts. Apache에 의해 PHP 스크립트는 정적 HTML 페이지보다 최소 2에서 느리게 서비스된다. 더 많은 정적 HTML 페이지와 더 적은 스크립트를 노력하라. 31. Your PHP scripts are recompiled every time the scripts are cached. Install a PHP caching product to increase performance by 25-100% by removing compile times. PHP 스크립트는 않으면 매번 재 컴파일된다. 컴파일 시간을 제거함으로써 25~100%만큼의 성능을 증가시키기 PHP 캐싱 도구를 설치하라. 32. Cache as much as Use memcached - memcached is a high-performance memory object caching intended to speed up dynamic web applications by alleviating database OP code caches are useful so that your script does have to be compiled on every request 가능한 한 많이 memcached를 사용하라. memcached는 고성능 메모리 객체 캐싱 시스템이다. 33. working with strings and you need to check that the is either of a certain length you’d understandably would want use the strlen() function. This function is pretty quick since operation does not perform any calculation but merely return the known length of a string available in the zval structure C struct used to store variables in PHP). However because is a function it is still somewhat slow because the call requires several operations such as lowercase & hashtable lookup by the execution of said function. In some instance you improve the speed of your code by using an isset() 문자열을 가지고 작업하며 문자열이 특정 길이인지 확인할 필요가 있을 때, 함수를 쓸 것이다. 이 함수는 계산없이 zval 구조체에서 사용할 수 이미 알려진 문자열 길이를 반환하기 때문에 매우 빠르다. 그러나 strlen()이 때문에 여전히 조금 느리다. 왜냐하면 함수 호출은 언급된 함수의 실행 lowercase와 hashtable lookup같은 여러 개의 연산을 호출하기 때문이다. 어떤 경우에는 트릭을 이용하여 코드의 스피드를 증가시킬 수도 있다. Ex. if < 5) { echo "Foo is too short"; } vs. if (!isset($foo{5})) { echo "Foo is too short"; } Calling isset() happens to be faster then strlen() because unlike strlen(), isset() is a language construct and not a function meaning that it's execution does not require function lookups and lowercase. This means you have virtually no overhead on top of the actual code that determines the string's length. isset()을 호출하는 것은 strlen()과는 달리 isset()이 언어 기본문법이고 함수가 아니기 때문에 함수 찾와 lowercase 작업을 필요로 하지 않으므로 strlen()보다 더 빠를 수도 있다. 이것은 가상적으로 문자열의 길이를 결정하는 실제 코드에 과부하가 없다는 것을 의미한다. 34. When incrementing or decrementing the value of the variable $i++ happens to be a tad slower then ++$i. This is something PHP specific and does not apply to other languages, so don't go modifying your C or Java code thinking it'll suddenly become faster, it won't. ++$i happens to be faster in PHP because instead of 4 opcodes used for $i++ you only need 3. Post incrementation actually causes inthe creation of a temporary var that is then incremented. While pre-incrementation increases the original value directly. This is one of the optimization that opcode optimized like Zend's PHP optimizer. It is a still a good idea to keep in mind since not all opcode optimizers perform this optimization and there are plenty of ISPs and servers running without an opcode optimizer. 변수 $i의 값을 증가시키거나 감소키킬 때, $i++은 ++$i보다 조금 더 느릴 수 있다. 이것은 PHP의 특징이고다른 언어에는 해당되지 않으니 좀 더 빨라질 것을 기대하면서 C나 Java 코드를 바꾸러 가지 마라. 안 빨라질 것이다. ++$i는 PHP에서 좀 더 빠른데 그것은 $i++에 4개의 opcode가 사용되는 대신에 3개만 필요하기 때문이다. 후증가는 사실 증가될 임시변수의 생성을 초래한다. 반면에 전증가는 원래 값을 직접 증가시킨다.이것은 opcode가 Zend의 PHP optimizer처럼 최적화하는 최적화 기법의 하나이다. 모든 opcode optimizer들이 이 최적화를 수행하는 것은 아니고 많은 ISP와 server들이 opcode optimizer없이 수행되고 있기 때문에 명심하는 게 좋을 것이다. 35. Not everything has to be OOP, often it is too much overhead, each method and object call consumes a lot of memory. 모든 것이 OOP일 필요는 없다. 종종 그것은 너무 많은 과부하가 된다. 각각의 메쏘드와 객체 호출은 메모리를 많이 소비한다. 36. Do not implement every data structure as a class, arrays are useful, too 모든 데이터 구조를 클래스로 구현하지 마라. 배열도 유용하다. 37. Don't split methods too much, think, which code you will really re-use 메쏘드를 너무 많이 분리하지 마라. 어떤 코드를 정말 재사용할지 생각해봐라. 38. You can always split the code of a method later, when needed 항상 메쏘드의 코드를 나중에 필요할 때 분리할 수 있다. 39. Make use of the countless predefined functions 수많은 미리 정의된 함수를 활용해라. 40. If you have very time consuming functions in your code, consider writing them as C extensions 매우 시간을 소비하는 함수가 있다면, C 확장으로 작성하는 것을 고려해봐라. 41. Profile your code. A profiler shows you, which parts of your code consumes how many time. The Xdebug debugger already contains a profiler. Profiling shows you the bottlenecks in overview 당신의 코드를 프로파일해봐라. 프로파일러는 코드의 어떤 부분이 가장 많은 시간을 소비하는지 보여준다. Xdebug 디버거는 이미 프로파일러를 포함하고 있다. 프로파일링은 전체적인 병목을 보여준다. 42. mod_gzip which is available as an Apache module compresses your data on the fly and can reduce the data to transfer up to 80% Apache 모듈로 사용가능한 mod_gzip은 실행 중에 데이터를 압축하여 전송할 데이터를 80%까지 줄일 수 있다. 43. Excellent Article about optimizing php by John Lim John Lim의 PHP를 최적화하는 것에 관한 뛰어난 글 |




