Skip to content

Instantly share code, notes, and snippets.

@zeraf29
zeraf29 / insertion_sort.js
Created March 26, 2017 15:13
칸아카데미-삽입정렬 구현 소스
var insert = function(array, rightIndex, value) {
for(var j = rightIndex;
j >= 0 && array[j] > value;
j--) {
array[j + 1] = array[j];
}
array[j + 1] = value;
};
var insertionSort = function(array) {
@zeraf29
zeraf29 / recursive.js
Created April 2, 2017 14:36
재귀 팩토리얼
var factorial = function(n) {
// n이 0일 경우 1을 리턴(항등원)
if(n===0){
return 1;
}
// 0이 아닐 경우, n보다 작은 수의 팩토리얼 계산(재귀함수 호출)
// 최종의 경우 n*(n-1)!=n! 와동일
return n*factorial(n-1);
};
// Returns the first character of the string str
var firstCharacter = function(str) {
return str.slice(0, 1);
};
// Returns the last character of a string str
var lastCharacter = function(str) {
return str.slice(-1);
};
@zeraf29
zeraf29 / power.js
Created April 23, 2017 09:07
칸 아카데미. 재귀를 활용한 거듭제곱(정수일 경우)
var isEven = function(n) {
return n % 2 === 0;
};
var isOdd = function(n) {
return !isEven(n);
};
var power = function(x, n) {
//println("Computing " + x + " raised to power " + n + ".");
@zeraf29
zeraf29 / hanoi.js
Last active April 20, 2020 00:38
칸 아카데미 - 하노이의 탑 소스
// This library exposes 3 functions:
// hanoi.moveDisk(fromPeg, toPeg); This moves the top disk from the fromPeg to the toPeg
// hanoi.getSparePeg(fromPeg, toPeg); This returns the remaining peg that isn't the fromPeg or the toPeg
// hanoi.isSolved(toPeg); This returns true if all disks are on toPeg and no invalid moves have been used
var hanoi = (function() {
var sprites = function() {
"use strict";
// A minimalist sprite library for KA visualizations.
// Devin Balkcom, June 2014.
@zeraf29
zeraf29 / mergesort.js
Created June 11, 2017 14:26
병합정렬
// Takes in an array that has two sorted subarrays,
// from [p..q] and [q+1..r], and merges the array
var merge = function(array, p, q, r) {
// This code has been purposefully obfuscated,
// as you'll write it yourself in next challenge.
var a=[],b=[],c=p,d,e;for(d=0;c<=q;d++,c++){a[d]=array[c];}for(e=0;c<=r;e++,c++){b[e]=array[c];}c=p;for(e=d=0;d<a.length&&e<b.length;){if(a[d]<b[e]){array[c]=a[d];d++;} else {array[c]=b[e]; e++;}c++; }for(;d<a.length;){array[c]=a[d];d++;c++;}for(;e<b.length;){array[c]=b[e];e++;c++;}
};
// Takes in an array and recursively merge sorts it
@zeraf29
zeraf29 / merge.js
Created July 2, 2017 13:29
병합 구현
// Takes in an array that has two sorted subarrays,
// from [p..q] and [q+1..r], and merges the array
var merge = function(array, p, q, r) {
var lowHalf = [];
var highHalf = [];
var k = p;
var i;
var j;
for (i = 0; k <= q; i++, k++) {
@zeraf29
zeraf29 / SimpleUrlGoogle.cs
Created October 15, 2017 15:27
구글 short url api 를 이용한 단축 url 생성 매서드(C#)
public static string SimpleUrl(string orgUrl)
{
string shortUrl = "";
string key = "google key"; //Google 단축키 Key URL
var request = (HttpWebRequest)WebRequest.Create("https://www.googleapis.com/urlshortener/v1/url?key=" + key);
//google simple url api 로 key 값 전달
request.ContentType = "application/json";
request.Method = "POST";
request.ContentType = "application/json";
@zeraf29
zeraf29 / running_app.sh
Created November 14, 2017 02:51
Checking already running shell or not
#!/bin/bash
# JINHYUP KIM
cd /data/program/bin #move to directory
pid=`ps -ef | grep "Programname" | grep -v 'grep' | awk '{print $2}'`
#Get PID for checking already running or not
#ps -ef : Get information about running process. -e: Every proecss's , -f: Detail Information
# | grep "Programname" : Find process contained "Programname" pattern on "ps -ef" result.
# | grep -v 'grep': Get result of not included 'grep'. Can get process info except "grep" searching process.
# | awk '{print $2}' : Get information of second($2) value in "ps -ef | grep "Programname" | grep -v 'grep'". $2(second) value is PID.
if [ -z $pid ] # -z: checking string size is zero or not. size is zero = true. (If pid size zero, this prgram is not running now)
@zeraf29
zeraf29 / expdb.sh
Last active November 23, 2017 11:42
Oracle expdb sample
expdp system/systempw directory=oradir dumpfile=oraback.dmp logfile=exp.log schemas=SCHEMANAME CONTENT=METADATA_ONLY
#for all export data, User system account.
#directory : What you create directory on Oracle upper step.
#dumpfile : Dump file will be made using this name on 'dirtory' location
#logfile : making log file
#schemas : select schema what you want exporting
#CONTENT=METADATA_ONY : Only export metadata (not records)