Skip to content

Instantly share code, notes, and snippets.

View ocowchun's full-sized avatar
🏠
Working from home

ocowchun(Ben Yeh) ocowchun

🏠
Working from home
View GitHub Profile
@ocowchun
ocowchun / nested_loop_join.txt
Last active July 7, 2019 13:36
nested loop join
for tuple r in R:
for tuple s in S:
emit, if r and s match
@ocowchun
ocowchun / main.py
Created August 15, 2017 12:49
Find text feature using pandas
import pandas as pd
file_path = 'your-file-path'
df = pd.read_csv(file_path)
df['code_snippet'] = df['content'].str.find('\n```\n') > 0
pattern = r'!\[.*\]\(.*\)'
df['image'] = df['content'].str.contains(pattern)
@ocowchun
ocowchun / peter-prime-number.js
Created August 14, 2017 23:19
peter-prime-number.js
console.log(i); // Because we assign value to `i` after this line, it will print `undefined`.
//I like extract the max number as a variable, for example `var max = 100`
for (var i = 1; i <= 100; i++) {
var check = true;
// I don't understand the logic here?
for (var j= 2; j <=6; j++) {
if(i%j ==0) {
check =false;
}
}
@ocowchun
ocowchun / expensiveComputeChild.js
Created July 8, 2017 13:53
Async perform expensive function
function foo() {
var i = 0;
while (i < 10000000) {
i = i + 1;
if (i % 3000000 === 0) {
}
}
return i;
}
@ocowchun
ocowchun / install.md
Created February 23, 2017 15:12
Install python3 and pandas
@ocowchun
ocowchun / pandas101.py
Created February 23, 2017 15:11
basic usage of pandas using python3
# Basic Uage of Pandas
## 讀取資料
```py
df = pd.read_csv('olympics.csv', index_col = 0, skiprows = 1)
```
## 選擇與過濾資料
```py
# 回傳第一筆資料
@ocowchun
ocowchun / install.md
Last active January 17, 2017 03:08
How to install querycsv in mac

querycsv.py

This document will explain how to install querycsv, a tool to help you query csv file using sql.

#open terminal

$ which brew

# if console output `brew not found`, install homebrew first, else skip this command
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
@ocowchun
ocowchun / sitemap.rake
Created November 2, 2016 10:01
update sitemap
namespace :sitemap do
desc "unzip sitemap.xml.gz and upload to s3"
task upload: :environment do
gz_file_path=Rails.root.join('public', 'sitemap.xml.gz')
file_path=Rails.root.join('public', 'sitemap.xml')
Zlib::GzipReader.open(gz_file_path) do |gz|
File.open(file_path, 'w') { |file| file.write(gz.read) }
end
upload_to_s3
end
@ocowchun
ocowchun / search.rb
Last active September 4, 2016 15:16
how to separate your search code in rails model and controller
class Book < ActiveRecord::Base
def self.search(options)
# implement your search
end
end
class BooksController < ApplicationController
def search
options=params[:keyword]
@books=Book.search(options)
@ocowchun
ocowchun / getInstances.js
Created August 25, 2016 03:55
Get AWS EC2 instances information from specify AutoScalingGroup
var AWS = require('aws-sdk');
var autoscaling = new AWS.AutoScaling();
var ec2 = new AWS.EC2();
var AutoScalingGroupNames = ['your-asg-name'];
autoscaling.describeAutoScalingGroups({
AutoScalingGroupNames: AutoScalingGroupNames
}, function(err, data) {
var instances = data.AutoScalingGroups[0].Instances;
var instanceIds = instances.map(instance => instance.InstanceId);