Skip to content

Instantly share code, notes, and snippets.

@layus
layus / extract.py
Created January 6, 2015 20:50
INGInious-related script that also extract the filename of an archive.
#!/usr/bin/python
# This Python file uses the following encoding: utf-8
import re
import sys
import json
import base64
# Retrieves the input data from INGInious and open input file
try:
archive = {}
@layus
layus / run
Last active August 29, 2015 14:12
A (INGInious) `run` file that works around missing tar and unzip binaries.
#!/bin/bash
extract () {
if [ -f $1 ] ; then
case $1 in
*.tgz)
# simulate missing tar command.
python -c "import tarfile; tarfile.open(\"$1\", 'r:gz').extractall(path=\"$2\");"
#tar xzf "$1" -C "$2"
;;
@layus
layus / postswitch
Last active August 29, 2015 14:15
Autorandr postswitch hook
#!/bin/bash -x
config="$1"
primary="eDP1"
secondary="eDP1"
case "$config" in
docked)
primary="DP1-1"
@layus
layus / migration
Last active August 29, 2015 14:16
A script to refactor INGInious codebase for pip pacakging.
#!/bin/bash
mod=(backend common frontend)
mkdir inginious
git mv templates static "${mod[@]}" inginious
# fix all imports names
sub='"s/\<\(backend\|common\|frontend\)\(\.\|\>\)/inginious.&/g"'
find . -name '*.py' | parallel -m "sed -i $sub"
@layus
layus / A. Description.md
Last active June 23, 2016 12:39
xserver.conf improvements via smart antiquotations.

This example shows how the generation of xserver.conf is impacted by the modification of semantics for antiquotations in multiline indented strings.

Three versions are presented here:

  • xserver.conf: The old version
  • xserver.conf-smart: The new version, note how many blank lines are removed, and block properly indented.
  • xserver.conf-smart-fixed: The version obtained with the new semantics after modifications from improve-x11.diff, in particular removing some cruft that reindents(!) blocks.

In particular, xserver.conf.diff shows the differences between xserver.conf and xserver.conf-smart-fixed.

diff --git a/pkgs/development/interpreters/python/interpreter.nix b/pkgs/development/interpreters/python/interpreter.nix
index 3683543..cf5a3fa 100644
--- a/pkgs/development/interpreters/python/interpreter.nix
+++ b/pkgs/development/interpreters/python/interpreter.nix
@@ -10,13 +10,15 @@ let
inherit (stdenv) lib;
+ override = overrides: (import ./interpreter.nix { inherit pkgs stdenv python overrides; }).pkgs;
+
@layus
layus / epsonEcoTank.nix
Created March 15, 2017 18:58
Partial nixos config for Epson EcoTank printers.
{ pkgs, ... }:
{
# Enable CUPS to print documents.
services.printing = {
enable = true;
drivers = [ pkgs.epson-escpr ];
browsing = true;
defaultShared = true;
};
@layus
layus / kde-chromium.nix
Created November 20, 2017 20:55
Minimalistic kde setup to test chromium integration.
# Build & run with
# NIXOS_CONFIG=$(pwd)/kde-chromium.nix nix-build '<nixpkgs/nixos>' -A vm
# ./result/bin/run-nixos-vm
{config, pkgs, ...}:
{
services.xserver = {
enable = true;
layout = "be";
xkbOptions = "eurosign:e";
@layus
layus / Readme.md
Last active February 3, 2018 00:14
Prefetch nix packages and update files in place

This bash script updates a package version and source hash directly in the source files.

It uses unsafeGetAttrPos to find the files to edit, which in turn require to get access to the real attrset. This is why we have to define the overlays.

@layus
layus / sqlite3_analyzer.sql
Created August 7, 2018 13:03
Tup database analysis after building firefox (867MB!)
/** Disk-Space Utilization Report For db
Page size in bytes................................ 4096
Pages in the whole file (measured)................ 211706
Pages in the whole file (calculated).............. 211706
Pages that store data............................. 211706 100.0%
Pages on the freelist (per header)................ 0 0.0%
Pages on the freelist (calculated)................ 0 0.0%
Pages of auto-vacuum overhead..................... 0 0.0%
Number of tables in the database.................. 11