Skip to content

Instantly share code, notes, and snippets.

@grav
grav / gist:5468757
Created April 26, 2013 17:04
One way of getting all tracks for an artist with the Cocoa Spotify API! Oh lawd ...
NSURL *artistUrl = [NSURL URLWithString:AebersoldSpotifyUri];
[SPArtistBrowse browseArtistAtURL:artistUrl inSession:[SPSession sharedSession] type:SP_ARTISTBROWSE_NO_TRACKS callback:^(SPArtistBrowse *artistBrowse) {
[SPAsyncLoading waitUntilLoaded:artistBrowse timeout:10.0 then:^(NSArray *loaded, NSArray *notLoaded) {
for(SPAlbum *a in artistBrowse.albums){
[SPAlbumBrowse browseAlbumAtURL:a.spotifyURL inSession:[SPSession sharedSession] callback:^(SPAlbumBrowse *albumBrowse) {
[SPAsyncLoading waitUntilLoaded:albumBrowse timeout:10.0 then:^(NSArray *loadedItems, NSArray *notLoadedItems) {
for(SPTrack *t in albumBrowse.tracks){
NSLog(@"%@",t);
}
}];
(require '[clojure.java.io :as io])
(defn save-url [url filename]
(let [in (io/input-stream (io/as-url url))
out (io/output-stream (io/as-file filename))]
(io/copy in out)))
@grav
grav / gist:d8f44d1a2ad527e764dc
Last active August 29, 2015 14:08
Get Xcode path from AppCode settings
import javax.xml.xpath.*;
import org.xml.sax.InputSource;
public class XcodePath {
public static void main(String[] args){
String appcodeOptions = System.getProperty("user.home") + "/Library/Preferences/appCode30/options/other.xml";
String xpathExpression = "/application/component[@name='XcodeSettings']/option[@name='selectedXcode']/@value";
XPathFactory xpathFactory = XPathFactory.newInstance();
XPath xpath = xpathFactory.newXPath();
@grav
grav / gist:5d36a83c6c32c05ed1d1
Last active August 29, 2015 14:20
promises and clojurescript
(defn setup-midi!
[]
(.then (.requestMIDIAccess js/navigator)
(fn [midi-access]
(.forEach (.-outputs midi-access)
(fn [o]
(let [name (.-name o)]
(when (= "IAC"
(apply str (take 3 name)))
(.then (.open o)
@grav
grav / gist:57fd2c4da27edfdd1467
Last active August 29, 2015 14:24
replete build instructions
git clone https://github.com/clojure/clojurescript
cd clojurescript
brew install maven # for building clojurescript
./script/build
cd ..
(defn js-iterator-to-vec
[it]
(loop [a []]
(if-let [v (-> (.next it)
(.-value))]
(recur (conj a v))
a)))
@grav
grav / create-reminder.swift
Last active January 29, 2016 12:36
Creating an EKReminder
// remember to
// import EventKit
let s = EKEventStore.init()
s.requestAccessToEntityType(EKEntityType.Reminder) { (comp, e) -> Void in
print(comp,e)
let r = EKReminder.init(eventStore: s)
r.title = "Testreminder!"
let d = NSDate.init().dateByAddingTimeInterval(60)
let a = EKAlarm.init(absoluteDate: d)
@grav
grav / osc.py
Last active June 19, 2016 19:45
Simple oscillator in python, using pyext (http://grrrr.org/research/software/py/)
class osc(pyext._class):
t = 0.0
f = 0.0
def bang_3(self):
print "SR:",self._samplerate(),"BS:",self._blocksize(),"F:",self.f
def _dsp(self):
# if _dsp is present it must return True to enable DSP
echo -e "\n\n------------ select from ms sql"
sqlcmd -S geotesterapache.cloudapp.net -U sa -P xxx -d skm_test_db -Q "select top 1 * from matrikel"
echo -e "\n\n------------ try parsing the spatial data"
export C_STR='MSSQL:driver=ODBC Driver 13 for SQL Server;server=geotesterapache.cloudapp.net;database=skm_test_db;UID=sa;PWD=xxx;tables=matrikel'
ogrinfo --debug on "$C_STR" -sql "select top 1 * from matrikel"
echo -e "\n\n------------ try querying through postgresql"
service postgresql start
psql -c "create database geotest encoding=UTF8 template=template0;"
import SimpleHTTPServer
import SocketServer
import urllib
import re
class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
match = re.search('^/proxy.ashx?\?url=(.+)$',self.path)
if match:
self.send_response(200)