Skip to content

Instantly share code, notes, and snippets.

View daeyun's full-sized avatar

Daeyun Shin daeyun

View GitHub Profile
#!/bin/bash
rand_highlight() { tr -dc $1 < /dev/urandom | head -c$2 | sed -e ''s/$3/`printf "\033[32m\033[40m$4\033[0m"`/g'';echo; }; rand_highlight shin 500 shin shin
@daeyun
daeyun / x86_note_1.md
Last active December 11, 2015 19:09
random x86 note

If you see this error when compiling a 32 bit x86 assembly code with the -m32 flag on a 64 bit environment, install gcc-multilib.

/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc
collect2: error: ld returned 1 exit status
@daeyun
daeyun / s3-jekyll-sync.md
Last active December 11, 2015 19:18
managing a jekyll site on s3/cloudfront

testing

jekyll --server 8080 --auto

publishing

jekyll build

s3cmd sync _site/ s3://www.daeyunshin.com --add-header 'Cache-Control: max-age=300' --delete-removed --reduced-redundancy --acl-public --cf-invalidate

# check if s is a subsquence of S
def checkSubsequence(s, S):
idx = 0
for char in s:
if idx >= len(S):
return False
while char != S[idx]:
idx += 1
if idx >= len(S):
return False
@daeyun
daeyun / lisBigger.py
Created September 15, 2013 00:16
length of longest increasing subsequence
#!/usr/bin/python
def lisBigger(prev, A):
if len(A) == 0:
return 0
max = lisBigger(prev, A[1:])
if A[0] > prev:
L = 1 + lisBigger(A[0], A[1:])
if L > max:
max = L
return max
@daeyun
daeyun / longestPalindromeLength.py
Last active December 23, 2015 02:29
find the length of the longest palindrome subsequence in O(n^2)
#!/usr/bin/python
class LongestPalindrome:
def longestPalindrome(self, string):
self.string = string
self.LP = {}
return self.longestPalindrome_(0, len(self.string) - 1)
def longestPalindrome_(self, i, j):
if (i, j) in self.LP:
return self.LP[(i, j)]
@daeyun
daeyun / boggle.cpp
Last active December 27, 2015 21:49
C++ Boggle solver. Perform BSF on a graph of 26 vertices.
/* Author: Daeyun Shin */
#include<map>
#include<cassert>
#include<queue>
using namespace std;
map<char, map<char, bool> > graph;
int boggle(int board[4][4], const char * word) {
// populate the graph
for (int i = 0; i < 4; i++) {
public class Main {
public static void main(String[] args) throws IOException {
SocketChannel socketChannel = SocketChannel.open();
try {
socketChannel.connect(new InetSocketAddress("localhost", 10100));
} catch (IOException e) {
// Connection error
}
% DEFORM_SURFACE_TPS - Given a set of control points and mapping
% coefficients, compute a deformed surface f(S) using a thin plate spline
% radial basis function phi(r) as shown in [1].
%
% Usage: [fX, fY, fZ] = deform_surface_tps(X, Y, Z, control_points, ...
% mapping_coeffs, poly_coeffs)
%
% Arguments:
% X, Y, Z - h by w matrices of X, Y, Z components of the
% surface.
def levelsum(L, k):
if L.__class__ == int:
return L
total = 0
for element in L:
total += level_sum(element, k+1)
if k == 0:
return total