This file contains hidden or 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
qs = qs.extra( | |
select={'key_is_null': sort_key+' IS NULL'}, | |
order_by = ['-key_is_null', sort_key] | |
) |
This file contains hidden or 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
/** | |
* It is actually possible to trigger a download upon return from a GET or POST Ajax request. | |
* Source: http://stackoverflow.com/questions/16086162/handle-file-download-from-ajax-post/23797348#23797348 | |
* Here with jQuery $ajax(). | |
**/ | |
$.ajax({...}) | |
.then(function(response, status, xhr) { | |
/* Check for a filename */ | |
var filename = ""; |
This file contains hidden or 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 readable_size(num): | |
"""Change number of bytes to human-readable file size""" | |
for unit in ['','K','M','G','T','P','E','Z']: | |
if abs(num) < 1024.0: | |
return "%3.1f%sB" % (num, unit) | |
num /= 1024.0 | |
return "%.1f%s%s" % (num, 'Yi', 'B') |
This file contains hidden or 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
#!/usr/bin/env julia | |
// Attempt to implement simple homomorphic encryption | |
function generate_key(N=20) | |
key = rand(0:1, N) | |
while countnz(key) == 0 # on ne veut pas une cle avec 0 partout | |
key = rand(0:1, N) | |
end | |
return key |
This file contains hidden or 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
# Hierholzer's algorithm for Eulerian graphs # | |
""" | |
EXAMPLE | |
V = [1,2,3,4,5,6] | |
E = [(1,2),(2,3),(3,4),(4,5),(5,6),(6,1),(2,6),(6,4),(4,2)] | |
returns [1, 2, 6, 4, 2, 3, 4, 5, 6, 1] | |
V = ["AA","AB","BC","CD","DE","EF"] | |
E = [("AA","AB"),("AB","BC"),("BC","CD"),("CD","DE"),("DE","EF"),("EF","AA"),("AB","EF"),("EF","CD"),("CD","AB")] |
This file contains hidden or 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
# Deep search algorithm to find an Hamiltonian path in a graph | |
# (visiting every edge once and only once) | |
""" | |
EXAMPLES | |
V = ['AA','AB','BC','CD','DE','EF'] | |
E = [('AA','AB'),('AB','BC'),('BC','CD'),('CD','DE'),('DE','EF'),('EF','AA'),('AB','EF'),('EF','CD'),('CD','AB')] | |
returns [['AA','AB','BC','CD','DE','EF'], ['AB','BC','CD','DE','EF','AA'], ['BC','CD','DE','EF','AA','AB'], | |
['CD','DE','EF','AA','AB','BC'], ['DE','EF','AA','AB','BC','CD'], ['EF','AA','AB','BC','CD','DE']] |
This file contains hidden or 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
""" | |
A Python implementation of NNLS algorithm | |
References: | |
[1] Lawson, C.L. and R.J. Hanson, Solving Least-Squares Problems, Prentice-Hall, Chapter 23, p. 161, 1974. | |
Based on MATLAB's lsqnonneg function | |
Ported to Python by Klaus Schuch ([email protected]) and contributed by myself (especially unit tests). | |
""" |
This file contains hidden or 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
set.seed(100) | |
data = c(rnorm(1000,mean=2,sd=1),rnorm(400,mean=6,sd=1.5)) | |
# linear | |
plot(sample(data), rep(0,length(data)), pch=4) | |
# with hist | |
hist(data, freq=FALSE, breaks=100) | |
points(sample(data), rep(0,length(data)), pch=4) |
This file contains hidden or 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
/** | |
* Return a Map[String,Any] of the field -> value pairs of the attributes of a class `c`. | |
*/ | |
def classToMap(c: AnyRef): Map[String, Any] = | |
// 'fold' syntax, starting with an empty map | |
(Map[String, Any]() /: c.getClass.getDeclaredFields) {(a, f) => | |
f.setAccessible(true) | |
a + (f.getName -> f.get(c)) | |
} |
This file contains hidden or 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 java.io.FileInputStream | |
import java.nio.file.Paths | |
import play.api.http.HttpEntity | |
import akka.stream.scaladsl.StreamConverters | |
import play.api.mvc._ | |
import play.api.http.MimeTypes._ | |
import play.api.http.HeaderNames._ | |
import play.api.http.Status._ |
OlderNewer