Skip to content

Instantly share code, notes, and snippets.

View flyfy1's full-sized avatar

Song Yangyu flyfy1

View GitHub Profile
@flyfy1
flyfy1 / date_transformer
Last active August 11, 2020 16:05
file for parse from `ISO 8601` date into `yyyy-MM-dd HH:mm:ss` so that it's parsable by MySQL when imported as CSV
#!/usr/bin/ruby
source_path = ARGV[0]
target_path = ARGV[1]
puts "going to process file: #{source_path}"
puts "going to create file: #{target_path}"
fail "source file non edist" unless File.exist?(source_path)
fail "target file already edist" if File.exist?(target_path)
// in item order page
deliveryInfo = document.querySelector("#appOrders > div > table > tbody > tr > td > ul > li > div")
deliveryCompany = deliveryInfo.querySelector("span:nth-child(2)").innerText
deliveryID = deliveryInfo.querySelector("span:nth-child(4)").innerText
itemName = document.querySelector("#appOrders > div > table > tbody > tr > td > ul > li > table > tbody > tr > td.header-item.order-item-info > div > div.item-meta > a").innerText
totalPrice = document.querySelector("#appAmount > div > table > tbody > tr > td.total-count > div:nth-child(1) > div:nth-child(4) > table > tbody > tr > td > span > div").innerText.split('¥')[1]
console.log(`${itemName}\t${deliveryCompany}\t${deliveryID}\t\t\t\t${totalPrice}`)
@flyfy1
flyfy1 / get-geektime-links.js
Last active August 9, 2018 15:36
因为极客时间网页版上的专栏中,点开一篇文章在返回的时候,会重置上一个页面。这极大地影响了刷专栏的体验。这个脚本用来获取《极客时间》网页版的 标题、发布时间 和 连接,复制内容到剪贴版,用以直接粘贴进Excel / Google SpreadSheet 这样的程序
@flyfy1
flyfy1 / .railsrc
Last active November 19, 2017 15:10
Rails starter template: rspec / factory_bot / slim
# Put this file in your home foler
-d postgresql
-T
@flyfy1
flyfy1 / 1.callback.rb
Created May 15, 2017 03:31
Ruby Memory Leak Examples
module Logger
extend self
attr_accessor :output, :log_actions
def log(&event)
self.log_actions ||= []
self.log_actions << event
end
# This gist records the steps to setup a new Ubuntu Server
# User Setup - add user with sudo
sudo adduser $USERNAME
sudo adduser $USERNAME sudo
# Add SSH Login
mkdir ~$USERNAME/.ssh/
cat public_key > ~$USERNAME/.ssh/authorized_keys
chmod 500 -R ~$USERNAME/.ssh/
@flyfy1
flyfy1 / git_note.sh
Last active June 6, 2017 14:36
Collection of quick notes.. in bash
# Git Remove Merged Branch
git branch --merged | egrep -v "(^\*|master|dev)" | xargs git branch -d
# Git List branch, with commit id and message, ordered by last commit date
git for-each-ref --sort=committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'
# Remote the deleted branch in the remote `origin`
git remote prune origin
@flyfy1
flyfy1 / MontyHall.java
Created October 15, 2016 11:55
Java Simulation for the MontyHall Problem
import java.util.Random;
import java.util.Set;
import java.util.TreeSet;
public class MontyHall {
static Random rand = new Random();
public static void main(String args[]){
@flyfy1
flyfy1 / gist:15cd169339f4dac446039976c6e0390a
Last active July 16, 2016 13:29 — forked from jfreeze/gist:8894279
Get VI bindings in IEX (Elixir REPL)

VI bindings in iex:

brew install rlwrap # on OSX
echo "alias iex='rlwrap -a foo iex'" >> ~/.bash_profile
echo "set editing-mode vi" >> ~/.inputrc
source ~/.bash_profile

To run iex WITHOUT rlwrap

\iex

@flyfy1
flyfy1 / app-models-product_property_decorator.rb
Last active June 6, 2016 10:23
For Solidus: making Property selectable field
Spree::ProductProperty.class_eval do
belongs_to :value_object, class_name: 'Spree::PropertyValue', foreign_key: :value_id
before_validation { self.value = value_object.value if value_id and changes[:value_id] }
end