Skip to content

Instantly share code, notes, and snippets.

@cv711
cv711 / vimkeybindings.js
Last active June 1, 2021 11:32
violentmonkey-vimkeybindings
// ==UserScript==
// @name vimkeybindings
// @namespace renevier.fdn.fr
// @author arno <arenevier@fdn.fr>
// @licence GPL/LGPL/MPL
// @description use vim keybingings (i, j, k, l, …) to navigate a web page.
// ==/UserScript==
/*
* If you're a vim addict, and you always find yourself typing j or k in a web
* page, then wondering why it just does not go up and down like any good
@cv711
cv711 / d3_annotations.js
Created August 16, 2013 10:27
Example of adding foreignObject tags in d3 chart, from a jsonp query. (ATTENTION: foreignObject not supported by IE, switched to rickshaw library for that)
$.getJSON("<url>?callback=?",function(data){
svg.selectAll(".names")
.data(data.entries.filter(function(d){ if(d.type == "SONG") return d;}))
.enter().append("foreignObject")
.attr("x",function(d){ return x(d.timestamp);})
.attr("y", height)
.attr("width",300)
.attr("height",margin.between)
.append("xhtml:div")
.attr("class","songLabels")
@cv711
cv711 / city_partial.js.erb
Last active December 19, 2015 14:08
Synchronize country and city selection in a form
<% if !@cities.blank? %>
$('#cityfield').html("");
$('#cityfield').html("<%=j collection_select(:resource,:CITY_ID,Country.find(1).cities,:id,:NAME, {:prompt =>'Select a city'})%>");
<%else%>
$('#cityfield').html("");
$('#cityfield').html("<%=j text_field :CITY_ID, :disabled%>");
<%end%>
@cv711
cv711 / gist:5875299
Last active April 15, 2023 07:01
SPARQL queries to get the names of cities of the world, based on population from Wikipedia
-- just the city resource
SELECT DISTINCT ?citylabel ?countrylabel ?pop
WHERE {
?city rdf:type dbpedia-owl:City.
?city rdfs:label ?citylabel.
?city dbpedia-owl:country ?country.
?country rdfs:label ?countrylabel.
?city dbpedia-owl:populationTotal ?pop .
FILTER ( lang(?countrylabel) = 'en' and lang(?citylabel) = 'en' and ?pop>10000)
@cv711
cv711 / gist:5766110
Created June 12, 2013 15:04
Sync choices in two (identical) select tags
$('select').on('change', function(e){
var index =$(':selected').first().index();
var second = $('select')[1];
var option = second.options[index];
option.selected = true;
})
@cv711
cv711 / gist:5591628
Created May 16, 2013 13:15
List all routes accessible in Ember.js app (from v 1.0.0-rc1)
//This will return objects corresponding to each segment that the route consists of.
App.Router.router.recognizer.recognize('/some_path')
//to see all the routes in your application – including nested routes.
App.Router.router.recognizer.names