Skip to content

Instantly share code, notes, and snippets.

View not-for-me's full-sized avatar
☺️
Fun coding time!

Woojin.joe not-for-me

☺️
Fun coding time!
View GitHub Profile
@not-for-me
not-for-me / CaseClass.scala
Last active December 28, 2015 08:49
Scala의 케이스 클래스 특징~
// 스칼라의 문법인 케이스 클래스와 패턴 매칭 코드로 살펴보기
// regular, non-encapsulated data structures 가 필요할 때 케이스 클래스 사용
// Programming In Scala 15장 예제 코드로 구성 됨
abstract class Expr
case class Var(name: String) extends Expr
case class Number(num: Double) extends Expr
case class UnOp(operator: String, arg: Expr) extends Expr
case class BinOp(operator: String, left: Expr, right: Expr) extends Expr
@not-for-me
not-for-me / Equaltest.scala
Created December 28, 2015 08:26
In Scala, '==' is equals with 'equals()'. Try to execute below code sniff on the repl.
case class Dummy(a: Int, b: Double)
val obj1 = Dummy(1, 10.0)
val obj2 = Dummy(2, 20.0)
val obj3 = Dummy(1, 10.0)
obj1 == obj2
obj1 equals obj2
obj1 == obj3
@not-for-me
not-for-me / EqualTest.java
Created December 28, 2015 08:14
In Java, 'equals' and '==' test code
public class EqualTest{
public static void main(String []args){
new EqualTest().test();
}
private void test() {
Dummy obj1 = new Dummy(1, 10.0);
Dummy obj2 = new Dummy(2, 20.0);
Dummy obj3 = new Dummy(1, 10.0);
System.out.println("obj1 == obj2: " + (obj1 == obj2) + " / obj1.equals(obj2): " + obj1.equals(obj2) );
@not-for-me
not-for-me / tail_rec_exp.c
Last active November 4, 2015 03:26
tail recursion version: two's exponential function
int _twoExponential(int exponent, int acc) {
if ( exponent == 0 ) {
return acc;
}
acc *= 2;
return _twoExponential(--exponent, acc);
}
int exponential(int num) {
@not-for-me
not-for-me / Rational.scala
Created October 5, 2015 06:33
스칼라의 클래스 선언 샘플
package nfm.ex06
/**
* Programming In Scala 2/e List 6.5 코드
* 분수 Class
* @param n 분자
* @param d 분모
*/
/* 스칼라에 있는 문법: Class에서 기본 생성자 선언 가능
float tempC;
int reading;
int tempPin = 0;
void setup()
{
Serial.begin(9600);
analogReference(INTERNAL);
}
void loop()
{
//Arduino Sample Code for SHT1x Humidity and Temperature Sensor
//www.DFRobot.com
//Version 1.0
#include <SHT1x.h>
// Specify data and clock connections and instantiate SHT1x object
#define dataPin 10
#define clockPin 11
SHT1x sht1x(dataPin, clockPin);
@not-for-me
not-for-me / writeXLS.py
Created October 20, 2014 07:42
Make Excel File with Python
# coding: utf-8
from xlwt import Workbook
book = Workbook()
sheet1 = book.add_sheet(u'Ex Sheet1')
sheet2 = book.add_sheet(u'Ex Sheet2')
sheet1.write(0,0, u'Name')
sheet1.write(0,1, u'Sex')
@not-for-me
not-for-me / readXLS.py
Created October 20, 2014 07:41
Python Program for reading xls
# coding: utf-8
from xlrd import open_workbook
wb = open_workbook('simple.xls')
for sheet in wb.sheets():
print(u'Sheet:' + sheet.name)
print("Number of Sheets: " + str(wb.nsheets))
@not-for-me
not-for-me / factorial.scala
Created October 2, 2014 16:44
Factorials
def factorial(n: Int): Int = {
def loop(acc: Int, n: Int): Int =
if (n == 0) acc
else loop(acc*n, n-1)
loop(1, n)
}