Skip to content

Instantly share code, notes, and snippets.

@dbridges
dbridges / CustomSortFilterProxyModel.py
Last active December 1, 2022 22:11
A subclass of QSortFilterProxyModel that implements custom filtering, especially useful for multicolumn filtering.
from PySide import QtGui
class CustomSortFilterProxyModel(QtGui.QSortFilterProxyModel):
"""
Implements a QSortFilterProxyModel that allows for custom
filtering. Add new filter functions using addFilterFunction().
New functions should accept two arguments, the column to be
filtered and the currently set filter string, and should
return True to accept the row, False otherwise.
@dbridges
dbridges / comments_list.html.slim
Last active March 15, 2018 21:25
Rails UJS and Stimulus Comment List
h1 Comments
.comment-list data-controller="comment-list"
ul.comments-list data-target="comment-list.commentList"
= render @comments
= form_with model: Comment.new, html: { data: { type: "html", action: "ajax:success->comment-list#onPostSuccess" } } do |form|
= form.text_area :message, data: { target: "comment-list.message" }
= form.submit "Post Comment"
@dbridges
dbridges / comments_controller.rb
Last active March 16, 2018 05:05
Rails UJS and Stimulus Comment List
class CommentsController < ApplicationController
def index
@comments = Comment.all
end
def create
@comment = current_user.comments.create(comment_params)
render @comment
end
@dbridges
dbridges / comment_list_controller.js
Last active March 15, 2018 21:25
Rails UJS and Stimulus Comment List
import { Controller } from "stimulus";
export default class extends Controller {
static targets = ["message", "commentList"]
onPostSuccess(event) {
let [data, status, xhr] = event.detail;
this.commentListTarget.innerHTML += xhr.response;
this.messageTarget.value = "";
}
$(".comment-list").append("<%= j render(@comment) %>");
$(".comment-list form textarea").val("");
year age births population adjustedBirths
2003 15 17520 2032351 0.862055816
2003 16 38152 2012581 1.895675255
2003 17 64671 2015547 3.208607887
2003 18 93595 2032257 4.605470666
2003 19 116222 1993831 5.829079797
2003 20 115473 2010652 5.743062449
2003 21 103090 2031746 5.073961017
2003 22 94870 2057360 4.611249368
2003 23 86886 2048153 4.242163549
@dbridges
dbridges / _comment.html.slim
Last active August 25, 2022 18:51
Stimulus.js and Rails remote forms with error handling
- # app/views/comments/_comment.html.slim
li data-controller="comment" data-action="click->comment#hello"
= "#{comment.message} by #{comment.user.email}"
var feedURLs = []string{
"https://blog.golang.org/feed.atom",
"http://feeds.kottke.org/main",
}
type feedResult struct {
feed *Feed
err error
}
func fetchFeeds(urls []string) ([]*Feed) {
// Create a channel to process the feeds
feedc := make(chan feedResult, len(urls))
// Start a goroutine for each feed url
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Example Feed</title>
<subtitle>A subtitle.</subtitle>
<link href="http://example.org/feed/" rel="self" />
<link href="http://example.org/" />
<id>urn:uuid:60a76c80-d399-11d9-b91C-0003939e0af6</id>
<updated>2003-12-13T18:30:02Z</updated>