Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

xullnn

🎯
Focusing
View GitHub Profile
@xullnn
xullnn / binary_s.rb
Last active Jun 30, 2017
Binary search _ caven
View binary_s.rb
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 Apr 27, 2018
Find the best destination combinations
View travel_destination.rb
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 Apr 27, 2018
the knapsack problem
View knapsack.rb
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
mango_seller_with_comments
View mango_seller_with_comments.rb
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 Jan 15, 2019
zhuolaobanmimatiaozhan
View decipher.rb
encoded_text = <<-MSG
snmft
ltslcnsnonjhmzemjizfsbjsenijmfsdn
cnfrnfsbtdftonftljnsndnljwjsbz
emndtzsnbfshmjslqjemjljwjsbz
hfndtzonmznmztijonfsluns
efnrnrfczjpjhmjslemtsl
btrjshmzqjczjcnqjifqnfslonfrnmjonjrnijemnxmn
mfnqnftonjqjxmnljemzrnslijrnrfczjwjsbzyfrjsljozkjsllj
dtzcnjwjsxznwfsefteftonzvzxmnqjifsqnzcnfqjgftlznijxmzczjhmjsllzt
@xullnn
xullnn / update_yaml.rb
Created Feb 21, 2019
Try updating a portion of a yaml file
View update_yaml.rb
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
View halfway_in_ls.md

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 Apr 17, 2019
practice html and css
View nutrition_facts.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<style>
html {
font-size: 32px;
font-family: "Helvetica Black", Helvetica;
}
View revised_nutrition_facts.html
<!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
Rot13 in Javascript
View rot13.js
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));