Skip to content

Instantly share code, notes, and snippets.

@jcasimir
jcasimir / sessions_and_conversations.markdown
Created September 11, 2011 23:07
Sessions and Conversations in Rails 3

Sessions and Conversations

HTTP is a stateless protocol. Sessions allow us to chain multiple requests together into a conversation between client and server.

Sessions should be an option of last resort. If there's no where else that the data can possibly go to achieve the desired functionality, only then should it be stored in the session. Sessions can be vulnerable to security threats from third parties, malicious users, and can cause scaling problems.

That doesn't mean we can't use sessions, but we should only use them where necessary.

Adding, Accessing, and Removing Data

@hendrikswan
hendrikswan / app.rb
Created December 20, 2011 21:29
sample sinatra mongodb service
require 'sinatra'
require 'mongoid'
require 'json'
require "sinatra/reloader" if development?
Mongoid.load!("mongoid.yml")
class Price
include Mongoid::Document
@trcarden
trcarden / gist:3295935
Created August 8, 2012 15:28
Rails 3.2.7 SSL Localhost (no red warnings, no apache config)
# SSL self signed localhost for rails start to finish, no red warnings.
# 1) Create your private key (any password will do, we remove it below)
$ openssl genrsa -des3 -out server.orig.key 2048
# 2) Remove the password
$ openssl rsa -in server.orig.key -out server.key
@staltz
staltz / introrx.md
Last active April 17, 2025 06:34
The introduction to Reactive Programming you've been missing
@rmehner
rmehner / delete-databases.js
Last active March 19, 2025 15:26
Delete all indexedDB databases
// Credit to @steobrien from https://gist.github.com/rmehner/b9a41d9f659c9b1c3340#gistcomment-2940034
// for modern browsers, this works:
const dbs = await window.indexedDB.databases()
dbs.forEach(db => { window.indexedDB.deleteDatabase(db.name) })
// for older browsers, have a look at previous revisions of this gist.
@paulirish
paulirish / what-forces-layout.md
Last active April 18, 2025 15:29
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
rubocop -a `git diff --name-only --cached | grep '\.rb'`
@Aerijo
Aerijo / making_language_grammar.md
Last active February 8, 2025 02:42
Guide to writing an Atom language grammar

A guide to writing a language grammar (TextMate) in Atom

Tree sitter

  • Atom is transitioning to an entirely new way of defining grammars using tree-sitter. This will be enabled by default quite soon now. It is theoretically faster and more powerful than regex based grammars (the one described in this guide), but requires a steeper learning curve. My understanding is that regex based grammars will still be supported however (at least until version 2), so this guide can still be useful. To enable it yourself, go to Settings -> Core and check Use Tree Sitter Parsers

Links for tree-sitter help:

@egstad
egstad / github-shop-ascii.js
Last active February 26, 2025 14:54
GitHub Shop: ASCII Effect
// __ ___ ___ ____ ____ ___ __ _ _ _ _ __ ___
// /__\ / __)/ __(_ _(_ _) / __) /__\ ( \( ( \/ /__\ / __)
// /(__)\\__ ( (__ _)(_ _)(_ ( (__ /(__)\ ) ( \ /(__)\\__ \
// (__)(__(___/\___(____(____) \___(__)(__(_)\_) \(__)(__(___/
// What you'll need...
// 1. A canvas: <canvas id="asciiCanvas"></canvas>
// 2. An image: <img id="image" src="" alt="">
// Fetch elements