Skip to content

Instantly share code, notes, and snippets.

View xullnn's full-sized avatar
🎯
Focusing

xullnn

🎯
Focusing
View GitHub Profile
@xullnn
xullnn / binary_s.rb
Last active June 30, 2017 09:44
Binary search _ caven
require 'benchmark'
def binary_search(arr, given_element)
length = arr.size
t = 1 # search times, used to locate every step's relative_position
relative_position = 0.5 # compared element's relative position, initialized as 0.5 (1/2)
current_index = (1/2.to_f * length)
e = arr[current_index] # the element compared with the given_element, first time it'll be the "middle" one
@xullnn
xullnn / travel_destination.rb
Last active April 27, 2018 13:16
Find the best destination combinations
class Destination
attr_accessor :name, :time_cost, :weight
def initialize(name,time_cost,weight)
@name = name
@time_cost = time_cost
@weight = weight
end
end
class Schedule
@xullnn
xullnn / knapsack.rb
Last active April 27, 2018 13:16
the knapsack problem
class Item
attr_accessor :name, :weight, :price
end
class Knapsack
attr_accessor :items, :capacity, :table
def initialize(capacity)
@items = []
@capacity = capacity
@xullnn
xullnn / mango_seller_with_comments.rb
Last active May 4, 2018 08:35
mango_seller_with_comments
class Person
attr_accessor :name, :is_seller, :friends
def initialize
@name = ('a'..'z').to_a.sample(5).join.capitalize!
@is_seller = false
@friends = []
end
end
def make_friends(n)
@xullnn
xullnn / decipher.rb
Last active January 15, 2019 07:29
zhuolaobanmimatiaozhan
encoded_text = <<-MSG
snmft
ltslcnsnonjhmzemjizfsbjsenijmfsdn
cnfrnfsbtdftonftljnsndnljwjsbz
emndtzsnbfshmjslqjemjljwjsbz
hfndtzonmznmztijonfsluns
efnrnrfczjpjhmjslemtsl
btrjshmzqjczjcnqjifqnfslonfrnmjonjrnijemnxmn
mfnqnftonjqjxmnljemzrnslijrnrfczjwjsbzyfrjsljozkjsllj
dtzcnjwjsxznwfsefteftonzvzxmnqjifsqnzcnfqjgftlznijxmzczjhmjsllzt
@xullnn
xullnn / update_yaml.rb
Created February 21, 2019 07:58
Try updating a portion of a yaml file
f = File.open("./example.yaml", "w")
100000.times do |n|
str = "user_#{n}:\n id: #{n}\n score: 0\n"
File.write("./example.yaml", str, mode: "a")
end
def find_position(target, file_obj)
file_obj.pos = file_obj.read =~ Regexp.new(target)
end
@xullnn
xullnn / halfway_in_ls.md
Created April 12, 2019 03:35
Halfway in LS

Halfway in my Launch School journey

I've just finished Database course in Launch School(hereinafter refer as LS), it's about half of its core curriculum. I prefer to call LS as a journey, because life in LS is more than what we do in a traditional "school".

Thanks to Internet

I live in a very small city in China, and I never knew or cared about anything about programming until 28. But thanks to Internet, I met LS. I was deeply drawn by LS's pedagogy. Instead of selling you the course urgently, LS provides a free preparatory course and advises you to make the decision after you've evaluated your feelings about the pre-course and you are agree with their pedagogy.

What I appreciate about LS

@xullnn
xullnn / nutrition_facts.html
Last active April 17, 2019 12:30
practice html and css
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<style>
html {
font-size: 32px;
font-family: "Helvetica Black", Helvetica;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<style>
html {
font-size: 23px;
font-family: sans-serif;
font-weight: lighter;
@xullnn
xullnn / rot13.js
Created May 5, 2019 09:51
Rot13 in Javascript
const LOWER_START = 97;
const UPPER_START = 65;
const LOWER_END = LOWER_START + 26;
const UPPER_END = UPPER_START + 26;
function newAsciiOf(char) {
var newAscii = char.charCodeAt() + 13;
if (/[a-z]/.test(char) && newAscii >= LOWER_END) {
newAscii = (LOWER_START + (newAscii % LOWER_END));