Skip to content

Instantly share code, notes, and snippets.

View grimen's full-sized avatar

Jonas Grimfelt grimen

View GitHub Profile
@grimen
grimen / sqlalchemy-truncate_db.py
Created November 19, 2022 05:51 — forked from absent1706/sqlalchemy-truncate_db.py
Sqlalchemy: Truncate all tables
def truncate_db(engine):
# delete all table data (but keep tables)
# we do cleanup before test 'cause if previous test errored,
# DB can contain dust
meta = MetaData(bind=engine, reflect=True)
con = engine.connect()
trans = con.begin()
con.execute('SET FOREIGN_KEY_CHECKS = 0;')
for table in meta.sorted_tables:
con.execute(table.delete())
@grimen
grimen / index.js
Created May 5, 2021 04:13 — forked from stalniy/index.js
CASL + Objection
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:'
@grimen
grimen / SubArray.js
Last active December 17, 2015 10:29 — forked from xk/SubArray.js
// 20111028 jorge@jorgechamorro.com
// How to subclass Array
// In reply to https://gist.github.com/1100841/9c959db9314338a09c0f288c2c0ca5553816e400
function subArray () {
var nu = Array.prototype.slice.apply(arguments); // @grimen: Fixed to support `new Array(666)` (=> `[666]` instead of Array of size 666)
nu.__proto__= subArray.prototype;
return nu;
}
<html>
<head>
<title>Your page</title>
</head>
<body>
<div>Your content</div>
<script type="text/javascript">
var mpq=[];mpq.push(["init","0725059687a1080dffb343076224e1b1"]);(function(){var a=document.createElement("script");a.type="text/javascript";a.async=true;a.src=(document.location.protocol==="https:"?"https:":"http:")+"//api.mixpanel.com/site_media/js/api/mixpanel.js";var b=document.getElementsByTagName("script")[0];b.parentNode.insertBefore(a,b)})();
@grimen
grimen / Easy Background Grid
Last active October 14, 2015 00:47 — forked from NathalieLarsson/Easy Background Grid
More discrete theme.
html, body {
width: 100%;
height: 100%;
}
body {
outline: 1px dashed rgba(0, 0, 0, 0.2);
}
body:before {
One other cause is your :dependent callbacks.
class Blog < AR::Base
has_many :posts, :dependent => :destroy
end
This will iterate through every post and call #destroy on it. Use :delete_all if you want to just issue a single delete query. HOWEVER, this won't hit your destroy callbacks on Post.
class Blog < AR::Base
has_many :posts