Skip to content

Instantly share code, notes, and snippets.

View dance2die's full-sized avatar
🐰
Working

Sung M. Kim dance2die

🐰
Working
View GitHub Profile
public static Dictionary<string, List<string>> ConvertToDictionaryOptimized(List<Tuple> actorMovies)
{
var result = new Dictionary<string, List<string>>();
foreach (Tuple actorMovie in actorMovies)
{
if (result.ContainsKey(actorMovie.Actor))
{
var movies = result[actorMovie.Actor];
movies.Add(actorMovie.Movie);
internal class QuickUnionUF
{
private readonly int[] _id;
private readonly int[] _size;
public QuickUnionUF(int n)
{
_id = new int[n + 1];
_size = new int[n + 1];
for (int i = 0; i < n; i++)
@dance2die
dance2die / index.js
Created June 19, 2017 00:18
firstAttempt()
export default class DemoMain {
constructor() {
this.goodReadsURL = `https://www.goodreads.com/shelf/list.xml`;
this.q = `key=${apiConfig.goodreadsKey}&user_id=${apiConfig.goodreadsUserID}&page=1`;
this.url = `${this.goodReadsURL}?${this.q}`;
}
logResult(url) {
axios.get(url, { params: { format: "json" } })
.then((yqlResponse) => {
@dance2die
dance2die / index.js
Created June 19, 2017 00:23
thirdAttempt()
var proxify = require('proxify-url');
...
thirdAttempt() {
// GoodReads API returns result in "XML" format.
// "XML" is the "input" format fed into YQL
let proxyUrl = proxify(this.url, { inputFormat: 'xml' });
this.logResult(proxyUrl);
@dance2die
dance2die / index.js
Last active June 19, 2017 23:25
secondAttempt()
import YqlAjax from './yql_ajax';
...
secondAttempt() {
let yqlAjax = new YqlAjax();
yqlAjax.ajax(this.goodReadsURL)
.then((yqlResponse) => {
// DefiantJS XPath query for user shelf for "read" section.
@dance2die
dance2die / yql_ajax.js
Last active June 19, 2017 23:39
YqlAjax
var axios = require('axios');
var apiConfig = require('../apikey.js');
export default class YqlAjax {
ajax(url) {
const yqlUrl = "http://query.yahooapis.com/v1/public/yql";
let goodReadsURL = `${url}?key=${apiConfig.goodreadsKey}&user_id=${apiConfig.goodreadsUserID}&page=1`;
let q = `select * from xml where url="${goodReadsURL}"`;
return axios.get(yqlUrl, {
@dance2die
dance2die / reddit.js
Created June 25, 2017 14:10
Open Reddit Links using Javascript
// Get reddit links
var divs = document.querySelectorAll('a[data-event-action="title"]');
// Open all links
for (i = 0; i < divs.length; i++) { window.open(divs[i].href); };
// Move to next page
window.location.href= document.querySelector('.next-button a').href;
@dance2die
dance2die / app.js
Created July 8, 2017 23:11
Importing apiKeys.js and using it in other JavaScript file
import apiConfig from '../../apikeys';
...
getShelfBooksURL() {
// https://www.goodreads.com/api/index#reviews.list
let goodReadsURL = ` https://www.goodreads.com/review/list`;
let q = `v=2&key=${apiConfig.goodreadsKey}&id=${apiConfig.goodreadsUserID}&shelf=read&sort=date_started`;
return {goodReadsURL, q};
}
@dance2die
dance2die / .gitignore
Created July 8, 2017 23:09
.gitignore ignoring apiKeys.js
apiKeys.*
module.exports = {
"goodreadsKey": "your developer key",
"goodreadsSecret": "secrete",
"goodreadsUserID": 12345
}