Skip to content

Instantly share code, notes, and snippets.

View srakrn's full-sized avatar

Sirakorn Lamyai srakrn

View GitHub Profile

Keybase proof

I hereby claim:

  • I am srakrn on github.
  • I am srakrn (https://keybase.io/srakrn) on keybase.
  • I have a public key whose fingerprint is 5E3A 7301 F865 7A6A D9DA 3D14 B2D0 EC5D B743 C223

To claim this, I am signing this object:

def to_signed_bit(x):
return format(x & 0xff, '08b')
f = open('all_inputs_sra_test.txt', 'w')
f.write('A[8] shft[3] out[8]\n')
a_values = range(-128, 128)
shft_values = range(0, 8)
for a in a_values:
@srakrn
srakrn / python_oop_gcd.py
Last active December 12, 2017 12:17
A (bad) example on Python's OOP, both showing its OOP ability, and showing that not all problems needs implementation of OOP concept.
class GCDCalculator:
def __init__(self, x, y):
self.x = x
self.y = y
self.gcd = self.gcd_function(x, y)
def gcd_function(self, x, y):
while y:
x, y = y, x%y
return x
def selection_sort(l):
for i in range(len(l)-1):
minimum = l[i]
minimum_pos = i
for j in range(i+1, len(l)):
if l[j] < minimum:
minimum = l[j]
minimum_pos = j
l[i], l[minimum_pos] = l[minimum_pos], l[i]
return l
def bubble_sort(l):
for i in range(len(l)):
border = len(l)-i-1
for j in range(border):
if l[j] > l[j+1]:
l[j], l[j+1] = l[j+1], l[j]
return l
import random
l = [random.randint(1, 20) for _ in range(20)]
@srakrn
srakrn / IntToChar.cs
Created August 18, 2016 14:04
Int to Char (C#)
using System;
class IntToChar{
public static void Main(string[] args){
int a = 65;
char c = (char)a;
Console.WriteLine(c);
}
}
@srakrn
srakrn / boostcamp_day6_myWc.py
Created July 28, 2016 11:55
204111 Boost Camp Python Word Count
#############################################
#NAME: Sirakorn Lamyai
#ID: 5910500023
#PROGRAM: myWc.py
#DATE: 28 Jul 2016
#############################################
import sys
f = open(sys.argv[1])
plain = f.read()
@srakrn
srakrn / boostcamp_day6_myGrep.py
Created July 28, 2016 11:54
204111 Boost Camp Python Grep
#############################################
#NAME: Sirakorn Lamyai
#ID: 5910500023
#PROGRAM: myGrep.py
#DATE: 28 Jul 2016
#############################################
import sys
f = open(sys.argv[1])
keyword = sys.argv[2]
@srakrn
srakrn / boostcamp_day6_myGrader.py
Created July 28, 2016 11:53
204111 Boost Camp Grader
#############################################
#NAME: Sirakorn Lamyai
#ID: 5910500023
#PROGRAM: myGrader.py
#DATE: 28 Jul 2016
#############################################
import sys
def grade(score):
@srakrn
srakrn / boostcamp_day6_myCopy.py
Last active July 28, 2016 11:54
204111 Boost Camp Python Copy
#############################################
#NAME: Sirakorn Lamyai
#ID: 5910500023
#PROGRAM: myCopy.py
#DATE: 28 Jul 2016
#############################################
import sys
src = sys.argv[1]
des = sys.argv[2]