Skip to content

Instantly share code, notes, and snippets.

@jprante
jprante / jsonld.sh
Created December 7, 2012 10:03
JSON-LD in Elasticsearch
curl -XDELETE 'localhost:9200/jsonld'
curl -XPOST 'localhost:9200/jsonld'
curl -XPUT 'localhost:9200/jsonld/doc/1' -d '
{
"@context":
{
"dc": "http://purl.org/dc/elements/1.1/",
@wikier
wikier / SPARQLWrapper-HTTP-Digest-Auth-example.py
Last active March 29, 2018 20:30
SPARQLWrapper HTTP Digest Auth example
from SPARQLWrapper import SPARQLWrapper, JSON, DIGEST
sparql = SPARQLWrapper("http://example.org/sparql")
sparql.setHTTPAuth(DIGEST)
sparql.setCredentials('login', 'password')
sparql.setQuery("...")
sparql.setReturnFormat(JSON)
@hvtuananh
hvtuananh / unicode_csv.py
Created February 5, 2014 22:36
Python Unicode CSV Reader/Writer (fix writerow problem in Python docs)
#http://docs.python.org/2.7/library/csv.html
import csv, codecs, cStringIO
class UTF8Recoder:
"""
Iterator that reads an encoded stream and reencodes the input to UTF-8
"""
def __init__(self, f, encoding):
self.reader = codecs.getreader(encoding)(f)
@nitaku
nitaku / README.md
Last active November 22, 2018 22:09
ID-based force layout

d3.js's force layout works fine with index-based node references in links, since it substitutes them internally with the corresponding node from the nodes array. This simple approach is effective when we can refer to nodes by their index in the nodes array. But what if we have an ID for each node and we want links to refer to those IDs?

If we resolve the IDs into nodes before passing them to d3.js's force layout, everything works as expected. This example illustrates the technique by repurposing another example by Mike Bostock.

Each node is given a string ID (a letter), and each link uses them to refer to the nodes it connects to. The code iterates through the links array to resolve the references.

Like in the original example, nodes are placed in precomputed positions, are made draggable, and are made fixed (i.e. not subject to the force) when dragged.

@samaaron
samaaron / Reich Phase - Overtone
Last active December 26, 2019 20:29
Steve Reich's Piano Phase - Sonic Pi vs Overtone
(ns overtone.examples.compositions.piano-phase
(:use overtone.live
overtone.inst.sampled-piano))
;; Steve Reich's Piano Phase
(def piece [:E4 :F#4 :B4 :C#5 :D5 :F#4 :E4 :C#5 :B4 :F#4 :D5 :C#5])
(defn player
[t speed notes]
@MoritzStefaner
MoritzStefaner / .block
Last active January 20, 2020 10:46
Force-based label placement
license: apache-2.0
@zdavkeos
zdavkeos / walk_up.py
Created July 21, 2011 23:18
python walk_up - like os.walk, only works its way up instead of down
#!/bin/env python
"""
os.walk is an awesome generator.
However, I needed the same functionality,
only I wanted to walk 'up' the
directory tree.
This allows seaching for files
in directories directly above
@lambdamusic
lambdamusic / README.md
Last active November 30, 2020 17:20
Nature.com archive statistics
@ttscoff
ttscoff / sizes.rb
Last active July 12, 2021 03:33
sizes: Calculate and sort all filesizes for current folder
#!/usr/bin/env ruby
# Sizes - Calculate and sort all filesizes for current folder Includes
# directory sizes, colorized output Brett Terpstra 2019 WTF License
VERSION = "1.0.1"
require 'shellwords'
# Just including term-ansicolor by @flori and avoiding all the
# rigamarole of requiring multiple files when it's not a gem... - Brett
#
@basiszwo
basiszwo / github-apps.md
Last active November 25, 2022 04:15
Web, mobile and desktop apps for managing Github (Issues)