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
var obj = JSON.parse(s) | |
for (var i = 0; i < obj.data.length; i++) { | |
var item = obj.data[i]; | |
console.log(`created time ${item.created_time}, message ${item.message} id ${item.id}`) | |
} |
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 'json' | |
require 'ostruct' | |
json_object = JSON.parse(json_string, object_class: OpenStruct) | |
json_object.data.each { | |
|d| puts "created time: %s message: %s id: %s" % [d.created_time, d.message, d.id] | |
} |
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
// PuzzleList.java | |
import java.util.Iterator; | |
import java.util.List; | |
public class PuzzleList implements Iterable<Puzzle> { | |
private List<Puzzle> data; | |
public PuzzleList() { | |
super(); | |
} |
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 net.liftweb.json._ | |
case class Puzzle(created_time: String, message: String, id: String) | |
case class PuzzleData(data: List[Puzzle]) | |
implicit val formats = DefaultFormats | |
val parsed = puzzle_data.extract[PuzzleData] | |
for { | |
puzzle <- parsed.data |
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 json | |
jb = json.loads(jsonbblob) | |
from collections import namedtuple | |
print (jb['data'][0].keys()) | |
Puzzle = namedtuple('Puzzle', jb['data'][0].keys()) | |
puzzles = [Puzzle(*puz.values()) for puz in jb['data']] | |
for p in puzzles: |
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
jsonbblob = """ | |
{ | |
"data": [ | |
{ | |
"created_time": "2017-12-08T01:08:57+0000", | |
"message": "Love this puzzle. One of my four coke puzzles", | |
"id": "820882001277849_1805191182846921" | |
}, | |
{ | |
"created_time": "2017-12-07T20:06:14+0000", |
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 first_clear(arr, idx): | |
for i in range(idx, len(arr)): | |
if arr[i] == 0: | |
return i | |
return -1 | |
def find_all_primes_upto(n): | |
sieve = [0] * (n+1) | |
i = 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
import datetime | |
df = pd.DataFrame({'Month': [datetime.date(2008, i, 1).strftime('%B') for i in range(1,13)] * 3, | |
'visited': [False]*36}, | |
index= ['Alice']*12 + ['Bob']*12 + ['Bridgett']*12) | |
df = df.reset_index() | |
df [(df['index'] == 'Alice') & | |
((df['Month'] == 'February') | (df['Month'] == 'March') | (df['Month'] == 'April'))] | |
def make_regular(r, name): |
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
class Edge: | |
def __init__(self, fv, tv, name, weight): | |
self.fv = fv | |
self.tv = tv | |
self.name = name | |
self.weight = weight | |
def __repr__(self): | |
return '{}:{}:{}:{}'.format(self.fv, self.tv, self.name, self.weight) |
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
class Edge: | |
def __init__(self, fv, tv, name, weight): | |
self.fv = fv | |
self.tv = tv | |
self.name = name | |
self.weight = weight | |
def __repr__(self): | |
return '{}:{}:{}:{}'.format(self.fv, self.tv, self.name, self.weight) |