Skip to content

Instantly share code, notes, and snippets.

View growthcode's full-sized avatar

Hethe Berg growthcode

  • Outer space. Deep outer space.
View GitHub Profile
@knowtheory
knowtheory / datamapper_composite_index.rb
Created February 15, 2011 02:16
Demonstrating how to do composite indexes in DataMapper
require 'dm-core'
require 'dm-migrations'
DataMapper.setup(:default, "mysql://localhost/test")
class TotallyContrivedForThisExample
include DataMapper::Resource
property :id, Serial # already part of the primary key
property :plerp, String, :key => true # Adds this to the primary key
@brianjlandau
brianjlandau / gist:4162654
Created November 28, 2012 17:21
Setting up a Rails engine for MySQL, RSpec & Capybara

Setup RSpec and Capybara on a new Rails engine

  1. rails plugin new ENGINE_NAME --full --database=mysql

  2. Add to gemspec:

s.add_development_dependency 'rspec-rails'
s.add_development_dependency 'shoulda-matchers'
s.add_development_dependency 'capybara'
s.add_development_dependency 'database_cleaner'
@demisx
demisx / active_record_objects_autosave.md
Last active July 4, 2024 14:20
When Active Record Child Objects are Autosaved in Rails

belongs_to:

  1. Assigning an object to a belongs_to association does not automatically save the object. It does not save the associated object either.

has_one:

  1. When you assign an object to a has_one association, that object is automatically saved (in order to update its foreign key).
  2. In addition, any object being replaced is also automatically saved, because its foreign key will change too
  3. If either of these saves fails due to validation errors, then the assignment statement returns false and the assignment itself is cancelled.
  4. If the parent object (the one declaring the has_one association) is unsaved (that is, new_record? returns true) then the child objects are not saved. They will automatically when the parent object is saved.
@wesbos
wesbos / tab-trigger.js
Created November 16, 2015 19:33
How to properly get a TAB trigger working with Emmet inside of JSX
{
"keys": ["tab"],
"command": "expand_abbreviation_by_tab",
// put comma-separated syntax selectors for which
// you want to expandEmmet abbreviations into "operand" key
// instead of SCOPE_SELECTOR.
// Examples: source.js, text.html - source
"context": [
{
@jeroendesloovere
jeroendesloovere / install-redis.md
Last active November 27, 2023 09:58
install redis

Redis Installation

1. Download and install Redis

Copy/paste the following code block into your terminal.

# Downloading latest
wget http://download.redis.io/redis-stable.tar.gz
@kalpeshsingh
kalpeshsingh / pre-push
Last active April 26, 2024 04:31
A pre-push git hook that notify Amazon Chime group
#!/bin/sh
branch="$(git rev-parse --abbrev-ref HEAD)"
# get computer name to append in Chime message
username=$USER
# a branch name where you want to prevent git push. In this case, it's "master"
if [ "$branch" = "master" ]; then
echo "You can't commit directly to '"${branch}"' branch" # webstorm or intellij will show this as popup
@phaistonian
phaistonian / gpr.sh
Created January 26, 2021 09:04
alias gpr="sh gpr.sh"
#! /bin/bash
set -e
BRANCH=$(git rev-parse --abbrev-ref HEAD)
REMOTE=$(git remote get-url origin)
URL="$REMOTE/compare/$BRANCH?expand=1";
if [ "$BRANCH" = "master" ]
then
echo You must checkout a feature branch first