Skip to content

Instantly share code, notes, and snippets.

View if1live's full-sized avatar
πŸ’­
I may be slow to respond.

byunghoo.yu if1live

πŸ’­
I may be slow to respond.
View GitHub Profile
@if1live
if1live / happy_new_year.cpp
Created January 1, 2014 06:28
Happy new Year!
#include <cstdio>
#include <memory>
class Year {
public:
~Year() {
printf("Happy New Year!\n");
}
};
@if1live
if1live / shift.py
Created April 7, 2014 23:56
Implement shift operator without multiplication,division,bit operators
#!/usr/bin/env python
#-*- coding: utf-8 -*-
def left_shift(n):
return n + n
def is_bit_on(n, bit):
a = n % bit
b = n % left_shift(bit)
if not b:
@if1live
if1live / main.cpp
Created April 18, 2014 01:13
member method for specific class
#include <iostream>
#include <type_traits>
class Foo;
class Bar;
class API {
public:
template<typename T>
void call(const T &obj) {
@if1live
if1live / mouse_hook.py
Created May 7, 2014 04:05
Hook mouse event, then generate keyboard event.
#!/usr/bin/env python
#-*- coding: utf-8 -*-
from evdev import UInput, ecodes as e
from asyncore import file_dispatcher, loop
from evdev import InputDevice, categorize, ecodes
from select import select
dev = InputDevice('/dev/input/event4')
print(dev)
@if1live
if1live / closure_block.cpp
Created November 6, 2014 12:51
Closure blocks in C++
/*
http://en.wikipedia.org/wiki/C_Sharp_syntax#Closure_blocks
C#
public void Foo()
{
using (var bar = File.Open("Foo.txt"))
{
// do some work
throw new Exception();
@if1live
if1live / factorial.sh
Last active August 29, 2015 14:14
Factorial (shell script edition). Shell script is a function
#!/bin/bash
if [ -z "$1" ] || [ "1" == "$1" ]; then
echo 1
else
next=$(( $1 - 1 ))
prev=$(./factorial.sh $next)
echo $(( $prev * $1 ))
fi
@if1live
if1live / find_13_friday.cpp
Last active August 29, 2015 14:17
13일의 κΈˆμš”μΌ with C++ Template Meta Programming
/**
* https://twitter.com/Code_60/status/577062012250796032
* 였늘의 μ£Όμ œλŠ” "13일의 κΈˆμš”μΌ" μž…λ‹ˆλ‹€.
* Input : λ…„ 수
* Output : ν•΄λ‹Ή λ…„λ„μ˜ 13일의 κΈˆμš”μΌμ΄ ν¬ν•¨λœ μ›”
* ex) input : 2015 output : 3
*/
#include <cstdio>
#include <vector>
@if1live
if1live / solar_system_and_pluto.rb
Last active August 29, 2015 14:17
Print Pluto
# https://twitter.com/Code_60/status/579601136300101632
# 15/03/22
# 이번 μ£Όμ œλŠ” "νƒœμ–‘κ³„"μž…λ‹ˆλ‹€. μ–΄λ–€ ν”„λ‘œκ·Έλž¨μ΄λ“  μƒκ΄€μ—†μŠ΅λ‹ˆλ‹€.
# νƒœμ–‘κ³„μ— κ΄€λ ¨λœ ν”„λ‘œκ·Έλž¨μ„ μž‘μ„±ν•΄ μ£Όμ‹œλ©΄ λ˜κ² μŠ΅λ‹ˆλ‹€.
# 이번 λ―Έμ…˜μ€ "λ‚œλ…ν™”"μž…λ‹ˆλ‹€. μ΅œλŒ€ν•œ 읽기 νž˜λ“€κ³ , κΈ΄ μ½”λ“œκ°€ λ―Έμ…˜μ΄ λ˜κ² μŠ΅λ‹ˆλ‹€. 그럼, μ‹œμž‘!
#
# ν•˜μ§€λ§Œ λ‚œ λ‚œλ…ν™”μ— 관심 μ—†μ–΄μ„œ λͺ…왕성을 κΉ λ‹€.
solar_system = [:sun, :mercury, :venus, :earth, :mars, :jupiter, :saturn, :uranus, :neptune]
Solar,System,Contains,Fixed,Star,And,Some,Planets,ANd,Pluto = solar_system
puts "Pluto : #{Pluto}"
@if1live
if1live / create_markdown_delay.py
Created April 2, 2015 06:05
Creation time of python markdown object
#!/usr/bin/env python
#-*- coding: utf-8 -*-
'''
output sample
initial create : 0.0293490886688
re-create #1 : 0.00163388252258
re-create #2 : 0.00191903114319
졜초 μƒμ„±μ‹œμ—λ§Œ λŠλ¦¬λ‹€.
'''
@if1live
if1live / intlist_car_cdr.cpp
Last active August 29, 2015 14:19
int list + car/cdr (c++ template metaprogramming)
/*
type listλ₯Ό μ°Έμ‘°ν•΄μ„œ λ§Œλ“  int list와 car, cdr
reference : http://coliru.stacked-crooked.com/a/0af9789bed2adaf7
*/
#include <type_traits>
#include <climits>
template<int... Items>
struct intlist;