Skip to content

Instantly share code, notes, and snippets.

@shogonir
shogonir / quick_sort.c
Created June 2, 2015 05:16
quick sort implemented with C
int pivot_index (int n, int *a) {
int i;
for (i=1; i<n; i++) {
if (a[i] != a[0]) {
// pivot exists
return a[i] > a[0] ? i : 0;
}
}
// pivot not exists
return -1;
@shogonir
shogonir / insertion_sort.c
Created June 2, 2015 05:13
insertion sort implemented with C
void insertion_sort (int n, int *a) {
int i, j, swap;
for (i=1; i<n; i++) {
j = i-1;
while (j>=0 && a[j]>a[j+1]) {
swap = a[j];
a[j] = a[j+1];
a[j+1] = swap;
j--;
}
@shogonir
shogonir / exam1.py
Created July 8, 2015 06:30
I tried "Five programming problems every Software Engineer should be able to solve in less than 1 hour" in Python.
#! /usr/bin/env python
# -*- coding:utf-8 -*-
num_list = range(10)
# use for roop
list_sum = 0
for num in num_list :
list_sum += num
print 'list_sum counted with for roop :', list_sum
import sys
sys.path.append('../')
#! /usr/bin/env python
# -*- coding:utf-8 -*-
import sys
import numpy as np
from math import log
@shogonir
shogonir / Testlib.py
Created September 30, 2015 06:58
import example of Python
def library_name () :
return 'Testlib'
@shogonir
shogonir / test.py
Created September 30, 2015 07:00
import example of Python 2
#! /usr/bin/env python
# -*- coding:utf-8 -*-
import sys
sys.path.append('../')
from Testlib import *
print library_name()
import java.util.regex.Pattern;
import java.util.regex.Matcher;
public class CheckHatenaID {
public static void main (String[] args) {
String hatenaID = "shogonir";
Pattern p = Pattern.compile("[a-zA-Z][a-zA-Z0-9_\\-]{1,30}[a-zA-Z0-9]");
Matcher m = p.matcher(hatenaID);
boolean f = m.matches();
EditText editText = (EditText)findViewById(R.id.edit_text);
String editTextString = editText.getText().toString();
TextView textView = (TextView)findViewById(R.id.text_view);
textView.setText("EditText string = " + editTextString);
EditText editText = (EditText)findViewById(R.id.edit_text);
String editTextString = editText.getText().toString();
TextView textView = (TextView)findViewById(R.id.text_view);
textView.setText(getResources().getString(R.string.label, editTextString));