Skip to content

Instantly share code, notes, and snippets.

Don't worry about what anybody else is going to do. The best way to
predict the future is to invent it.
-- Alan Kay
Premature optimization is the root of all evil (or at least most of it)
in programming.
-- Donald Knuth
Lisp has jokingly been called "the most intelligent way to misuse a
computer". I think that description is a great compliment because it
@erickedji
erickedji / sparkJsonSchemaToStructTypeSource.js
Created March 30, 2021 16:44
Get spark DataFrame inferred schema with schema.json(), then use this to convert it to scala source (StructType, etc.)
// https://github.com/apache/spark/blob/0494dc90af48ce7da0625485a4dc6917a244d580/sql/catalyst/src/main/scala/org/apache/spark/sql/types/DataType.scala#L200
function sparkJsonSchemaToStructTypeSource(json) {
const types = ["string", "long", "double", "float", "boolean"];
if (typeof json === "string")
return `${json[0].toUpperCase()}${json.slice(1)}Type`;
switch (json.type) {
case "array":
@erickedji
erickedji / ninety-nine-lisp-problems.lisp
Created April 12, 2009 10:24
Ninety Nine Lisp Problems (30 answered)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Quatre-vingts-dix-neuf problèmes en LISP ;
; KEDJI Komlan Akpédjé <eric_kedji@yahoo.fr> ;
; Inspiré de 'Ninety-nine Lisp Problems', ;
; lui-même inspiré d'une liste de problèmes ;
; en Prolog par werner.hett@hti.bfh.ch ;
; Les étoiles après les numéros de problèmes ;
; indiquent le niveau de difficulté. ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@erickedji
erickedji / ninety-nine-scheme-problems.scm
Created April 12, 2009 10:23
Ninety Nine Scheme Problems (30 answered)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Quatre-vingts-dix-neuf problèmes en Scheme ;
; KEDJI Komlan Akpédjé <eric.kedji@gmail.com> ;
; http://erickedji.wordpress.com/ ;
; Elève ingénieur à l'ENSIAS ;
; ;
; Inspiré de 'Ninety-nine Lisp Problems' ;
; (www.ic.unicamp.br/~meidanis/courses/ ;
; mc336/2006s2/funcional/ ;
@erickedji
erickedji / polyglot.c
Created April 9, 2009 11:18
polyglot program: awesome!
(*O/*_/
Cu #%* )pop mark/CuG 4 def/# 2 def%%%%@@P[TX---P\P_SXPY!Ex(mx2ex("SX!Ex4P)Ex=
CuG #%* *+Ex=
CuG #%*------------------------------------------------------------------*+Ex=
CuG #%* POLYGLOT - a program in eight languages 15 February 1991 *+Ex=
CuG #%* 10th Anniversary Edition 1 December 2001 *+Ex=
CuG #%* *+Ex=
CuG #%* Written by Kevin Bungard, Peter Lisle, and Chris Tham *+Ex=
CuG #%* *+Ex=
@erickedji
erickedji / clean-gsmarena-data.js
Created March 15, 2019 20:36
Script de traitement du dataset gsmarena de kaggle pour brain.js
const fs = require("fs")
const parse = require("csv-parse")
const fileName = "gsmarena-phone-dataset.csv"
const fileContent = fs.readFileSync(fileName).toString()
parse(fileContent, {
columns: true,
skip_lines_with_error: true,
skip_empty_lines: true
}, function (err, records) {
const { loadOrTrain } = require("./utils")
const brain = require("brain.js")
const trainingData = require("./selectra-phone-dataset-numbers-only-normalized.json");
const net = new brain.NeuralNetwork({ hiddenLayers: [3] });
const stats = net.train(trainingData);
// const stats = loadOrTrain(net, trainingData);
[
{
"input": {
"Processeur": 1,
"Mémoire vive (RAM)": 0.3333333333333333,
"Mémoire interne": 1,
"Poids": 0.7326732673267327,
"Appareil photo frontal": 0.4375,
"Autonomie": 0.5058333333333334,
"Écran": 0.4506756756756757
https://selectra.info/telecom/guides/comparatifs/telephones-mobiles
function getPhoneData(tableDivEl) {
try {
let rawData = Array.from(tableDivEl.querySelectorAll("tr"))
.map(tr => ({
key: tr.querySelector("th").textContent,
value: parseInt(tr
.querySelector("td")
.textContent
// How to upgrade your users passwords in the DB without their intervention
//
// SHA-1 isn't strong enough to hash passwords with, but lots of people have a
// whole bunch of SHA-1'd passwords because they thought it was. You could use
// bcrypt or scrypt, but maybe in two years' time someone will tell you that's
// also not strong enough, and you'll want to upgrade.
//
// This sample demonstrates how you can remove weak password hashes from your
// user database, without needing the user to enter their password.