Skip to content

Instantly share code, notes, and snippets.

View nltesown's full-sized avatar

NLTESOWN nltesown

  • Paris, France
View GitHub Profile
@carlosefonseca
carlosefonseca / json2gfmtable.py
Last active June 24, 2016 04:41
Creates a GitHub Flavored Markdown table from a JSON array passed to the stdin. Accepts a list of column names as the argument for column ordering and filtering.
#!/usr/bin/env python3
# coding=utf-8
import json
import sys
# only reads from stdin
j = json.loads(sys.stdin.read())
# reads a list of column names from the argument "col1,col2" etc
@lizzie
lizzie / pubsub.js
Created February 20, 2013 05:06
Pub/Sub
var PubSub = {
subscribe: function(ev, callback) {
var calls = this._callbacks || (this._callbacks = {});
(this._callbacks[ev] || (this._callbacks[ev] = [])).push(callback);
return this;
},
publish: function() {
var args = Array.prototype.slice.call(arguments, 0);
@kconragan
kconragan / dabblet.css
Created April 26, 2012 17:51
Subtle CSS hatch pattern
body {
background-color:#f1f2f3;
background-image:
linear-gradient(rgba(0,0,0,.015) 1px, transparent 1px),
linear-gradient(0, rgba(0,0,0,.015) 1px, transparent 1px);
background-size:5px 5px;
background-position:-1px -1px, -1px -1px
}
@nltesown
nltesown / README.md
Last active July 13, 2019 21:30
Eager navbar jQuery plugin (aka half-sticky, aka sticky-up)

Eager navbar jQuery plugin

The navbar that's eager to show up and be sticky when you need it (scroll up) but apart from that acts naturally. Maybe I should call it something like half-sticky or sticky-up? Eager ain't bad either.

The gist of it: I wanted a script to give my top navbar this behavior:

  • When the navbar is visible (at the top of the document), as the document is scrolled down, the navbar follows until it finally gets out of view: in other words, no special behavior.
  • But whenever the document is scrolled up, the navbar immediately starts getting back into view as if its bottom was positioned just above the top of the viewport. Noteworthy: it does so by following the scroll exactly, which means that it can remain partially visible if the amount of scrolling up is not sufficient to show it completely. (No fancy animation to bring the element into view!)

CSS-wise, it is assumed that the navbar element is at the top of the layout and that it either is not positioned or has `position: relative;

@nltesown
nltesown / useful_lodash_expressions.md
Last active February 28, 2020 12:13
A collection (WIP) of useful lodash expressions

Useful lodash expressions

Object: group properties by a given key prefix

Problem: given an object where some properties have keys starting with an arbitrary prefix, we want to transform it so that the corresponding properties are grouped under a prefix-key, and the original keys are renamed to drop the prefix.

Use case: js2xmlparser transforms JSON to XML. Object properties under a @ key (by default) are output as XML attributes.

Source (data):

@nltesown
nltesown / cycles-ext-2.json
Last active March 11, 2020 15:32
Extension des cycles (rendez-vous réguliers) pour chrono-cycles
{
"Fenêtre sur les collections": [
{
"id": 11001,
"title": "Fossiles et autres traces du passé",
"dates": ["2018-12-21"]
},
{
"id": 11002,
"title": "Jacques Colombat, le cinéma des copains",
@gka
gka / App.svelte
Last active March 22, 2021 15:56
svelte 3 lazyload example
<h1>lazyload example</h1>
{#each [0,1,2,3,4,5,6,7,8,9] as i}
<p>Scroll down to load the images. Quo et qui laboriosam rerum. Animi et quia consequuntur quas sit eaque molestias. Accusamus voluptate nulla eligendi. Dolores labore ea asperiores ut voluptas dolorem. Cupiditate in enim quibusdam. Quas quae aliquam sed repellat laboriosam inventore est.</p>
<img alt="random image" use:lazyload src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAABCAQAAABeK7cBAAAAC0lEQVR42mNkAAIAAAoAAv/lxKUAAAAASUVORK5CYII=" data-src="https://picsum.photos/500/300/?image={i}" />
{/each}
<script>
import { lazyload } from './lazyload.js';
</script>
@dimfeld
dimfeld / mostVisibleElement.ts
Created May 28, 2020 19:25
Svelte IntersectionObserver action example
/**
* This is intended to be used with the svelte `use` syntax. It examines all
* child elements of the element that match `selector`, and calls the callback
* when the child element with the highest percentage overlap with the visible
* part of the container changes.
* <div use:mostVisibleElement={{ cb: setActive }}><section><section></div>
*/
export default function mostVisibleElement(
container: Element,
{ selector, cb }
@marianoviola
marianoviola / rollup.config.js
Last active April 16, 2022 05:04
Svelte style preprocessor using PostCSS
import svelte from 'rollup-plugin-svelte';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import buble from 'rollup-plugin-buble';
import uglify from 'rollup-plugin-uglify';
import postcss from 'postcss';
import postcssImport from 'postcss-import';
import postcssCssnext from 'postcss-cssnext';
const production = !process.env.ROLLUP_WATCH;
@Air-Craft
Air-Craft / jquery.plugin-template.js
Created October 20, 2011 10:56
jQuery Plugin Design Pattern/Template Improved!
// if (!window.L) { window.L = function () { console.log(arguments);} } // optional EZ quick logging for debugging
/**
* A modified (improved?) version of the jQuery plugin design pattern
* See http://docs.jquery.com/Plugins/Authoring (near the bottom) for details.
*
* ADVANTAGES OF EITHER FRAMEWORK:
* - Encapsulates additional plugin action methods without polluting the jQuery.fn namespace
* - Ensures ability to use '$' even in compat modes
*