Skip to content

Instantly share code, notes, and snippets.

View rik's full-sized avatar

Anthony Ricaud rik

View GitHub Profile
@rik
rik / CSVtoJSon.js
Last active February 29, 2024 09:12 — forked from codepo8/CSVtoJSon.js
OK, here is my function to turn CSV into JSON - what's yours?
function _csvRowToArray(csv) {
const csvRegex = /,(?=(?:(?:[^"]*"){2})*[^"]*$)/
const trimQuotes = /^"|"$/g
return csv.split(csvRegex).map(h => h.trim().replace(trimQuotes, ''))
}
function _csvRowToObject(headers, row) {
let currentRow = _csvRowToArray(row)
return Object.fromEntries(headers.map((header, i) => [header, currentRow[i]]))
}
import argparse
import csv
from collections.abc import Generator
from contextlib import contextmanager, closing
from io import TextIOWrapper
from typing import Any
from django.core.management.base import BaseCommand
from django.db import transaction
@rik
rik / index.html
Last active October 22, 2021 13:20 — forked from davidbgk/index.html
Opening details tag on hash/anchor
<!doctype html><!-- This is a valid HTML5 document. -->
<!-- Screen readers, SEO, extensions and so on. -->
<html lang="en">
<!-- Has to be within the first 1024 bytes, hence before the `title` element
See: https://www.w3.org/TR/2012/CR-html5-20121217/document-metadata.html#charset -->
<meta charset="utf-8">
<meta name="color-scheme" content="light dark">
<!-- Why no `X-UA-Compatible` meta: https://stackoverflow.com/a/6771584 -->
<!-- The viewport meta is quite crowded and we are responsible for that.
See: https://codepen.io/tigt/post/meta-viewport-for-2015 -->
@rik
rik / simulateTyping.js
Created September 1, 2017 14:30
Fake typing animation with async/await
async function nextFrame() {
return new Promise((resolve) => {
requestAnimationFrame(resolve)
})
}
async function randomDelay(min, max) {
const delay = Math.random() * (max - min) + min;
const startTime = performance.now()
while (performance.now() - startTime < delay) {
@rik
rik / jpegtran-directory.sh
Created July 14, 2011 22:28
Run jpegtran on every image in a directory (and subdirectories)
#!/usr/bin/env bash
function optimize
{
echo $1
filesize=`stat -f %z "$1"`
if [[ $filesize -lt 10000 ]]; then
jpegtran -copy none -optimize "$1" > "$1.bak"
echo "pet
else
@rik
rik / feed.xml
Created March 29, 2017 21:46
Microsoft Edge Dev Blog
<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" version="2.0">
<channel>
<title>Microsoft Edge Dev Blog</title>
<atom:link href="https://blogs.windows.com/msedgedev/feed/" rel="self" type="application/rss+xml"/>
<link>https://blogs.windows.com/msedgedev</link>
<description>Official blog of the Microsoft Edge Web Platform Team</description>
<lastBuildDate>Fri, 24 Mar 2017 16:06:25 +0000</lastBuildDate>
<language>en-US</language>
<sy:updatePeriod>hourly</sy:updatePeriod>
@rik
rik / gist:7637394
Last active December 29, 2015 07:39
In node_modules/mozilla-download/lib/download.js, add this in
function saveToTemp(err, url) {
var url = 'http://ftp.mozilla.org/pub/mozilla.org/b2g/nightly/2013-11-22-04-02-02-mozilla-central/b2g-28.0a1.multi.linux-x86_64.tar.bz2';
then
rm -rf b2g && make b2g && ./bin/gaia-marionette apps/system/test/marionette/media_playback_test.js
09-23 16:06:56.679 E/RILD ( 118): **RIL Daemon Started**
09-23 16:06:56.679 E/RILD ( 118): **RILd param count=1**
09-23 16:06:57.059 E/RILD ( 118): RIL_Init argc = 5 client = 0
09-23 16:06:59.879 E/RILPROXY( 112): Could not connect to rild socket, retrying: Connection refused
09-23 16:07:00.879 E/RILPROXY( 112): Could not connect to rild socket, retrying: Connection refused
09-23 16:07:01.879 E/RILPROXY( 112): Could not connect to rild socket, retrying: Connection refused
09-23 16:07:02.879 E/RILPROXY( 112): Could not connect to rild socket, retrying: Connection refused
09-23 16:07:03.429 W/RILC ( 118): RIL_onUnsolicitedSendResponse called before RIL_register
09-23 16:07:03.439 E/RILC ( 118): RIL_register: RIL version 6
09-23 16:07:03.439 E/RILC ( 118): s_registerCalled = 1, s_started = 1, RIL_getMaxNumClients = 1
@rik
rik / gist:6539602
Last active December 22, 2015 22:19
I have a conference call with 2 participants, I receive a 3rd call. This is the RIL log when I call telephony.active.hold() and incomingCall.answer()
D/RILC ( 113): UI --- RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE (15) ---> RIL [RID 0, token id 701, data len 0]
D/RILC ( 113): RID 0 corresponds to as_id 0
D/RILC ( 113): [RID 0] ReqList entries :
D/RILC ( 113): RIL_REQUEST_QUERY_AVAILABLE_NETWORKS (48), token id 630
D/RILC ( 113): RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE (15), token id 698
D/RILC ( 113): RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE (15), token id 701
D/RILC ( 113): RIL=>AMSS [ label = "cm_mm_call_sups_per_subs()" ];
D/RILC ( 113): RID 0 MID 0 Received CM_CALLSVC_COMMAND_CALLBACK : Req ID 852
D/RILC ( 113): RID 0 MID 0 Queued event CM_COMMAND_CALLBACK (12 bytes)
D/RILC ( 113): qcril_event_main(): 1 items on queue
@rik
rik / gist:6520487
Created September 11, 2013 07:50
Error while scraping
TypeError: Cannot read property 'body' of undefined
at Request._callback (/Users/rik24d/code/travis-scrape-gaia/node_modules/travis-ci/lib/travis-http.js:32:40)
at self.callback (/Users/rik24d/code/travis-scrape-gaia/node_modules/travis-ci/node_modules/request/index.js:148:22)
at Request.EventEmitter.emit (events.js:95:17)
at ClientRequest.self.clientErrorHandler (/Users/rik24d/code/travis-scrape-gaia/node_modules/travis-ci/node_modules/request/index.js:257:10)
at ClientRequest.EventEmitter.emit (events.js:95:17)
at CleartextStream.socketCloseListener (http.js:1523:9)
at CleartextStream.EventEmitter.emit (events.js:117:20)
at tls.js:688:10
at process._tickCallback (node.js:415:13)