Skip to content

Instantly share code, notes, and snippets.

Avatar

Jonas Grimfelt grimen

View GitHub Profile
@grimen
grimen / index.js
Created May 5, 2021 — forked from stalniy/index.js
CASL + Objection
View index.js
const { defineAbility } = require('@casl/ability');
const { rulesToQuery } = require('@casl/ability/extra');
const Knex = require('knex');
const { Model } = require('objection');
const { interpret } = require('@ucast/objection')
const { CompoundCondition } = require('@ucast/core')
const knex = Knex({
client: 'sqlite3',
connection: ':memory:'
View require.js
/* =========================================
IMPORTS
-------------------------------------- */
const fs = require('fs')
const path = require('path')
const _yaml = require('js-yaml')
View nvidia_gpu_crash_reboot_ubuntu.sh
sudo rmmod nvidia_uvm
sudo rmmod nvidia
sudo modprobe nvidia
sudo modprobe nvidia_uvm
View createFor.js
const createFor = (exported = {}) => {
return (defaults = {}) => {
const functions = {}
exported['defaults'] = {...defaults}
for (const [key, value] of Object.entries(exported)) {
if (typeof value === 'function') {
functions[key] = exported[key]
View combineStream.js
class CombinedStream extends stream.PassThrough {
constructor (...streams) {
super()
this._streams = streams
this._transformStream = undefined
this.on('pipe', this.onPipe)
}
@grimen
grimen / generators-test.js
Last active Jan 23, 2019
Experiments with Node.js Generator API - partially requires Node 10.
View generators-test.js
/* =========================================
IMPORTS
-------------------------------------- */
const fs = require('fs')
const { promisify } = require('util')
sleep = promisify(setTimeout)
@grimen
grimen / streams-test.js
Last active Jan 23, 2019
Experiments with Node.js Stream API.
View streams-test.js
/* =============================================
Dependencies
------------------------------------------ */
const debug = require('debug')
const chalk = require('chalk')
const { Readable, Writable, Transform, pipeline } = require('stream')
View debug.py
import coloredlogs, logging
# TODO: find library similar to `debug` in Node/NPM
def debug(name):
logger = logging.getLogger(name)
coloredlogs.install(level='DEBUG', logger=logger)
View samples.csv
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
url
https://images.asos-media.com/products/asos-golden-floral-bardot-midi-dress/7609569-1-multi?$XXL$
https://s3.amazonaws.com/markable-demo/zalando-images/7ce24b994834e0a616c5f501fc5b4907.jpg
View foo.json
This file has been truncated, but you can view the full file.
{
"catalog": {
"product": [
{
"programname": "Rebecca Minkoff & Ben Minkoff",
"programurl": "http://www.rebeccaminkoff.com",
"catalogname": "RebeccaMinkoff.com - Product Catalog",
"lastupdated": "2016-07-21 15:19:04.832",
"name": "Safety Pin Pendant",