Skip to content

Instantly share code, notes, and snippets.

View CreatiCoding's full-sized avatar
🎯
I may be slow to respond.

정석호 CreatiCoding

🎯
I may be slow to respond.
View GitHub Profile
@CreatiCoding
CreatiCoding / js_sort.js
Last active October 27, 2018 19:41
js sort solution 완주하지 못한 선수
// https://programmers.co.kr/learn/courses/30/lessons/42576
function solution(p, c) {
var size = c.length;
// 이렇게 하면 오류 발생
// p.sort((a,b)=>(a < b));
// 이렇게 하면 속도 느림
// p.sort((a,b)=>(a.localeCompare(b)));
// 속도 제일 빠르고 정확함
p.sort((a,b)=>(a < b ? -1 : (a > b ? 1 : 0)));
c.sort((a,b)=>(a < b ? -1 : (a > b ? 1 : 0)));
@CreatiCoding
CreatiCoding / printDivToPdf.js
Last active January 27, 2021 09:18
[javascript] Div to html in chrome
function printElement(ele, w = 800, h = 400){
var divContents = document.querySelector(ele).innerHTML;
var printWindow = window.open('', '', `height=${h},width=${w}`);
printWindow.document.write('<html><head><title>NoName</title>');
printWindow.document.write('</head><body >');
printWindow.document.write(divContents);
printWindow.document.write('</body></html>');
printWindow.document.close();
printWindow.print();
}
@CreatiCoding
CreatiCoding / install-node-12.sh
Last active May 18, 2019 07:07
[bash] install node 10 in ubuntu including about auth for npm directory.
sudo apt-get install -y curl
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y nodejs
OUTPUT="$(npm config get prefix)"
echo "$OUTPUT"
if [ "$OUTPUT" == "/usr/local" ]; then
OUTPUT="$(sudo chown -R $USER /usr/local)"
@CreatiCoding
CreatiCoding / promiseAllWithFor.js
Created July 27, 2018 00:32
[Node.js] Promise.All with for loop
// It is bad case about using Promise.All
let value = [1,2,3,4,5];
var promises = [];
for(let i=0;i<5;i++){
promises.push(
((data)=>{
return new Promise((resolve, reject)=>{
setTimeout(() => {
@CreatiCoding
CreatiCoding / requestWithPromise.js
Created July 27, 2018 00:27
[Node.js] request with promise
const request = require('request');
new Promise((resolve, reject)=>{
console.log(1);
resolve(new Promise((resolve, reject)=>{
request({url:'http://www.naver.com'},()=>{
console.log(2);
resolve(3);
});
}));
}).then(data=>{
@CreatiCoding
CreatiCoding / helloworld.c
Created July 26, 2018 09:55
hello world!
#include <stdio.h>
int main(){
printf("hello world!\n");
return 0;
}
@Dammmien
Dammmien / dfs.js
Last active February 22, 2022 11:37
Depth First Search (DFS) Graph Traversal in Javascript
const nodes = [
{
links: [ 1 ], // node 0 is linked to node 1
visited: false
}, {
links: [ 0, 2 ], // node 1 is linked to node 0 and 2
visited: false
},
...
];
@alexpchin
alexpchin / restful_routes.md
Last active November 12, 2024 08:50
7 Restful Routes
URL HTTP Verb Action
/photos/ GET index
/photos/new GET new
/photos POST create
/photos/:id GET show
/photos/:id/edit GET edit
/photos/:id PATCH/PUT update
/photos/:id DELETE destroy
@geedew
geedew / node-rm-rf.js
Last active February 3, 2021 12:36
Removing a directory that is not empty in NodeJS
var fs = require('fs');
var deleteFolderRecursive = function(path) {
if( fs.existsSync(path) ) {
fs.readdirSync(path).forEach(function(file,index){
var curPath = path + "/" + file;
if(fs.lstatSync(curPath).isDirectory()) { // recurse
deleteFolderRecursive(curPath);
} else { // delete file
fs.unlinkSync(curPath);
}
@mitchwongho
mitchwongho / Docker
Last active September 23, 2024 12:09
Docker 'run' command to start an interactive BaSH session
# Assuming an Ubuntu Docker image
$ docker run -it <image> /bin/bash