-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjson and gist.html
137 lines (137 loc) · 7.83 KB
/
json and gist.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<title></title>
<meta name="Generator" content="Cocoa HTML Writer">
<meta name="CocoaVersion" content="1138.32">
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px 'Gill Sans'; color: #000000}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000; min-height: 12.0px}
p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #d21610}
p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000}
p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #737373}
p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco}
span.s1 {color: #4350c3}
span.s2 {color: #032ec3}
span.s3 {color: #737373}
span.s4 {color: #053df5}
span.s5 {color: #d21610}
span.s6 {color: #000000}
span.s7 {color: #008225}
span.Apple-tab-span {white-space:pre}
</style>
</head>
<body>
<p class="p1">json and gist</p>
<p class="p2"><br></p>
<p class="p3">// 2011 Till Bovermann</p>
<p class="p3">// http://tangibleauditoryinterfaces.de<span class="Apple-converted-space"> </span></p>
<p class="p3">// http://tai-studio.org<span class="Apple-converted-space"> </span></p>
<p class="p3">// http://LFSaw.de<span class="Apple-converted-space"> </span></p>
<p class="p2"><br></p>
<p class="p3">// working:</p>
<p class="p3">// <span class="Apple-tab-span"> </span>+ list all gists for a specific user (well, currently only the first 30...)</p>
<p class="p3">// <span class="Apple-tab-span"> </span>+ get content of a gist by its id</p>
<p class="p3">// <span class="Apple-tab-span"> </span>+ edit/push gist (no file renaming, no file removal for now)</p>
<p class="p3">// <span class="Apple-tab-span"> </span>+ fork a gist (as long as it's not yours: It's a "feature" by github.)</p>
<p class="p3">// <span class="Apple-tab-span"> </span>+ delete a gist</p>
<p class="p2"><br></p>
<p class="p3">// I purposfully did not add the username and password to the class. If that feels annoying to you, please tell me why it is wise to do so and not to tackle security issues. Also, please tell me how I should handle auth strings in curl... I'm unsure about that currently.</p>
<p class="p2"><br></p>
<p class="p3">// if the following fails for you, please check if you have to update wslib's curl method by the one in<span class="Apple-converted-space"> </span></p>
<p class="p3">//<span class="Apple-tab-span"> </span>json/extString-curl.scd</p>
<p class="p2"><br></p>
<p class="p2"><br></p>
<p class="p4">q = ();</p>
<p class="p2"><br></p>
<p class="p3">// set your username / password here if you wanna create personalized gists, but its optional.</p>
<p class="p4">q.username = <span class="s1">nil</span>;</p>
<p class="p4">q.password = <span class="s1">nil</span>;</p>
<p class="p2"><br></p>
<p class="p2"><br></p>
<p class="p3">////////////////////////////// get existing gists /////////////</p>
<p class="p2"><br></p>
<p class="p2"><br></p>
<p class="p4">q.list = <span class="s2">Gist</span>.allGistsFor(<span class="s3">"LFSaw"</span>, q.username, q.password);</p>
<p class="p2"><br></p>
<p class="p3">// pretty print</p>
<p class="p4">q.list.do(<span class="s2">_</span>.prettyprint)</p>
<p class="p2"><br></p>
<p class="p3">// get content for all and print them out (this micht take a long time since it does an HTTP GET for every gist...)</p>
<p class="p4">q.list.do{<span class="s4">|gist|</span> gist.pull.prettyprint(<span class="s1">true</span>)}</p>
<p class="p2"><br></p>
<p class="p2"><br></p>
<p class="p4">{<span class="s4">|e|</span> <span class="s3">"% // %\n"</span>.postf(e, e.description); e.files.do{<span class="s4">|f|</span> <span class="s3">"\t%\n"</span>.postf(f.filename)};<span class="s3">""</span>.postln}</p>
<p class="p2"><br></p>
<p class="p3">// the gist dict for the latest gist of the user "LFSaw"</p>
<p class="p4">q.gist = q.list.first.pull</p>
<p class="p4">q.gist.filenames;</p>
<p class="p2"><br></p>
<p class="p3">// get content</p>
<p class="p4">q.gist[q.gist.filenames.asArray.first];</p>
<p class="p2"><br></p>
<p class="p2"><br></p>
<p class="p3">// the gist dict for an example gist for the OpenSynthDef world</p>
<p class="p4">q.gist = <span class="s2">Gist</span>(1113618).pull;</p>
<p class="p4">q.gist.files.asArray.first[<span class="s3">"content"</span>];</p>
<p class="p2"><br></p>
<p class="p3">// open in default Browser (requires wslib & osx)</p>
<p class="p4">q.gist.html_url.openInFinder;</p>
<p class="p2"><br></p>
<p class="p3">// You might want to evaluate it but do so on your own risk... someone could've put a bad unixCmd in there...</p>
<p class="p4">q.gist.files.asArray.first["content"].interpret.play; <span class="s5">// start the server first...</span></p>
<p class="p2"><br></p>
<p class="p3">// Open Documents for each file in the gist</p>
<p class="p4">q.gist.files.keysValuesDo{<span class="s4">|key, value|</span></p>
<p class="p4"><span class="Apple-tab-span"> </span><span class="s2">Document</span>(key.asString, value["content"])</p>
<p class="p4">}</p>
<p class="p2"><br></p>
<p class="p3">// fork that gist but mind you, you cannot fork your own gists for now!</p>
<p class="p4">q.forked = q.gist.fork(q.username, q.password)</p>
<p class="p2"><br></p>
<p class="p4">q.forked.id == q.gist.id <span class="s5">// should be different</span></p>
<p class="p2"><br></p>
<p class="p3">////////////////////////////// push new gists /////////////</p>
<p class="p2"><br></p>
<p class="p3"><span class="s6">( </span>// push a new gist</p>
<p class="p5"><span class="s4">var</span><span class="s6"> descr = </span>"My very-first SuperCollider gist"<span class="s6">;</span></p>
<p class="p4"><span class="s4">var</span> isPublic = <span class="s1">true</span>;</p>
<p class="p4"><span class="s4">var</span> content = Dictionary[</p>
<p class="p5"><span class="s6"><span class="Apple-tab-span"> </span></span><span class="s7">"SynthDef.sc" </span><span class="s6">-> </span>"SynthDef(\"out\", {Out.ar(0, FSinOsc.ar(247))})"</p>
<p class="p4">];</p>
<p class="p2"><br></p>
<p class="p4">q.gist = <span class="s2">Gist</span>.createAndPush(descr, content, isPublic, q.username, q.password);</p>
<p class="p4">)</p>
<p class="p2"><br></p>
<p class="p4">q.gist.delete(q.username, q.password)</p>
<p class="p2"><br></p>
<p class="p3">// not there anymore...</p>
<p class="p4">q.gist.pull</p>
<p class="p2"><br></p>
<p class="p3">// but you still have its last content:</p>
<p class="p4">q.gist.prettyprint</p>
<p class="p2"><br></p>
<p class="p3">// alter the string</p>
<p class="p5"><span class="s6">q.gist[</span><span class="s7">"SynthDef.sc"</span><span class="s6">] = </span>"SynthDef(\"out\", {Out.ar(0, LFPulse.ar(247))})"<span class="s6">;</span></p>
<p class="p2"><br></p>
<p class="p2"><br></p>
<p class="p3">// if you pushed this gist with a valid uid, you're able to push back your changes:<span class="Apple-converted-space"> </span></p>
<p class="p4">q.gist.push(q.username, q.password)</p>
<p class="p2"><br></p>
<p class="p2"><br></p>
<p class="p2"><br></p>
<p class="p3"><span class="s6">( </span>// post new anonymous gist</p>
<p class="p5"><span class="s4">var</span><span class="s6"> descr = </span>"My anonymous GIst gist"<span class="s6">;</span></p>
<p class="p4"><span class="s4">var</span> isPublic = <span class="s1">true</span>;</p>
<p class="p6"><span class="s4">var</span> content = Dictionary[</p>
<p class="p5"><span class="s6"><span class="Apple-tab-span"> </span></span><span class="s7">"SynthDef.sc"</span><span class="s6"> -> </span>"SynthDef(\"out\", {Out.ar(0, FSinOsc.ar(247); \\haha)})"</p>
<p class="p4">];</p>
<p class="p2"><br></p>
<p class="p4">q.gist = <span class="s2">Gist</span>.createAndPush(descr, content, isPublic);</p>
<p class="p2"><br></p>
<p class="p4">q.gist.id;</p>
<p class="p4">)</p>
</body>
</html>