Skip to content

Instantly share code, notes, and snippets.


Mathieu Agopian magopian

View GitHub Profile
magopian / gist:297d20e95b49daf3ad934e36b1855e82
Created Nov 28, 2018
elm decoder very helpful to debug decoders used in event handlers (thanks @JoelQ on the elm slack)
View gist:297d20e95b49daf3ad934e36b1855e82
module Main exposing (main)
import Html exposing (Html, text)
import Json.Decode as Decode exposing (Decoder)
loggingDecoder : Decoder a -> Decoder a
loggingDecoder realDecoder =
|> Decode.andThen
magopian / paste_table_data_parse_newlines.js
Created Apr 19, 2018
Paste table data from copying from excel/libreoffice, and change <br /> to newlines
View paste_table_data_parse_newlines.js
/* Quick and dirty experiment:
* Copy cells from a spreadsheet document (excel, libreoffice), and paste in a web page.
* Replace the <br /> in the cells with new lines, so when getting the innerHTML or the textContent,
* the result is "formatted".
document.addEventListener("paste", evt => {
const content = evt.clipboardData.getData("text/html");
console.log("content:", content);
const parser = new DOMParser();
const doc = parser.parseFromString(content, "text/html");
magopian / example.elm
Created Feb 9, 2018
syntax gripes with Elm
View example.elm
There's two ways to create a record in Elm: with the "type constructor" and with the "record syntax".
The fact that there's two ways to do the same thing is already a bit disconcerting, but the worst
part is that there's no way to do it and have the best of both worlds regarding naming (which is
great for clarity, maintenance and refactoring: think about grepping on names for example).
type alias Person = {
firstName: String,
magopian /
Created Oct 28, 2016
BBC micro:bit mood feedback
from microbit import *
def blink(img):
for i in range(5):
magopian /
Created Oct 12, 2016
Dirty script to get/filter attendees for the PyConFR 2016
# Needs the following libraries:
# requests==2.11.1
# unidecode
import csv
import requests
import sys
from collections import OrderedDict
from unidecode import unidecode
# Keys:
View 34-DifferentPort.elm
module Main exposing (..)
import Html
import Html.App
import Html.Events
import Http
import Json.Decode as Json exposing ((:=))
import Task
View Http.fromJson.elm
import Html
import Html.App
import Html.Events
import Http
import Json.Decode as Json exposing ((:=))
import Task
url : String
url = ""
magopian / aiohttp +
Last active Oct 4, 2019
experiments with python asyncio (all three are roughly the same speed as the werkzeug+pg version, as it's CPU bound, not IO bound: asyncio doesn't help in such cases)
View aiohttp +
"""start with:
gunicorn utilery.views_aiohttp_aiopg:app -b -w 4 -k aiohttp.worker.GunicornWebWorker"""
import asyncio
import json
import math
import time
import psycopg2
import psycopg2.extras
magopian / index.js
Created Mar 11, 2016
requirebin sketch
View index.js
// require() some stuff from npm (like you were using browserify)
// and then hit Run Code to run it on the right
var Validator = require('jsonschema').Validator;
var v = new Validator();
var schema = { "allOf" : [
{"type": "boolean"},
{"type": "string"}
console.log(v.validate("foobar", schema));
"""Reloads the `` code on save.
Put simple turtle instructions in the `` file,
and they'll be re-run (on a clean window) on each file save.
1/ put some turtle instructions in a `` file
(eg `turtle.forward(100)`)
2/ run `python` on a commandline
(no dependencies needed)
You can’t perform that action at this time.