This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
%matplotlib inline | |
plt.rcParams['figure.figsize'] = (10.0, 8.0) # set default size of plots | |
plt.rcParams['image.interpolation'] = 'nearest' | |
plt.rcParams['image.cmap'] = 'gray' | |
# for auto-reloading external modules | |
# see http://stackoverflow.com/questions/1907993/autoreload-of-modules-in-ipython | |
%load_ext autoreload | |
%autoreload 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getSubStringIndex(str, pattern) { | |
var indexArray = []; | |
for (var i = -1; (i = str.indexOf(pattern, i + 1)) !== -1; ) { | |
indexArray.push(i); | |
} | |
return indexArray; | |
} | |
function getSubStringIndexRecursion(lastIndex, str, pattern) { | |
var arr = []; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let list= ['abc', 'efg', ['abctest', ['aodb', 'kdka', ['dkkd', 'ad']]]]; | |
/* | |
1. find out string which contains 'a' output: [[0], [2, 0], [2, 1, 0], [2, 1, 1], [2, 1, 2, 1]] | |
2. regex | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fs from 'fs'; | |
import fbData from './facebook-data.json'; | |
let result = "id,message,likes\n"; | |
fbData.posts.data.map((post) => { | |
result += `${post.id},${post.message || ''},${post.likes.summary.total_count}\n`; | |
}); | |
fs.writeFileSync('facebook-ma.csv', result); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// I add the source where the snippet coming from at the begining. | |
// And the comment about what certain part of snippet is about at the end. | |
// https://github.com/g0v/ppt/blob/master/common/views/Governor.jsx | |
if (isLoading || errorMessage || !governor) { | |
return ( | |
<div style={styles.root}> | |
<section> | |
{ isLoading ? <Loading /> : | |
errorMessage ? errorMessage : |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
import * as FbApiActionCreators from '../actions/FbApiActionCreators.js'; | |
import {Parse} from 'parse'; | |
// convert messages in thread | |
function mapToMessages(message) { | |
return ({ | |
id: message.id, | |
created_time: message.created_time, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'yaml' | |
def file_reader_by_line(in_filename) # method for reading file line by line. | |
f = File.open(in_filename, 'r') | |
f.each_line do |line| | |
yield line | |
end | |
f.close | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'yaml' | |
def yaml_to_arr(in_filename = ARGV[0], out_filename = ARGV[1]) | |
complete_array = [] | |
arr_of_hash = YAML::load(File.read(in_filename)) | |
arr_of_hash.each do |hash| | |
temp_arr = [] | |
temp_arr.push (hash[:date] << "\t") | |
temp_arr.push (hash[:student_id] << "\t") | |
temp_arr.push (hash[:languages] << "\t") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fizzbuzz(size) | |
(1..size).each do |num| | |
result = '' | |
result << 'Fizz' if num % 3 == 0 | |
result << 'Buzz' if num % 5 == 0 | |
result = num.to_s if result == '' | |
yield result | |
end | |
end |