Skip to content

Instantly share code, notes, and snippets.

@tj
tj / app.js
Last active October 4, 2021 19:38
const http = require('http')
const rpc = require('./rpc')
/**
* Pets service.
*/
class Pets {
constructor(db = []) {
# Hello, and welcome to makefile basics.
#
# You will learn why `make` is so great, and why, despite its "weird" syntax,
# it is actually a highly expressive, efficient, and powerful way to build
# programs.
#
# Once you're done here, go to
# http://www.gnu.org/software/make/manual/make.html
# to learn SOOOO much more.
@SoHotSoup
SoHotSoup / .bash_profile
Created October 31, 2014 13:38
.bash_profile for mac web developers. Prompt includes username, current folder and git branch. Start simple server from current folder with server XXXX, where XXXX port number.
startServer()
{
open http://localhost:$1 | python -m SimpleHTTPServer $1
}
alias server=startServer
# Configure colors, if available.
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
c_reset='\[\e[0m\]'
@mislav
mislav / procs-vs-lambda.md
Last active March 26, 2021 18:34
Jim Weirich on the differences between procs and lambdas in Ruby

Jim Weirich:

This is how I explain it… Ruby has Procs and Lambdas. Procs are created with Proc.new { }, lambdas are created with lambda {} and ->() {}.

In Ruby 1.8, proc {} creates lambda, and Ruby 1.9 it creates procs (don't ask).

Lambdas use method semantics when handling parameters, procs use assignment semantics when handling parameters.

This means lambdas, like methods, will raise an ArgumentError when called with fewer arguments than they were defined with. Procs will simply assign nil to variables for arguments that were not passed in.

@piscisaureus
piscisaureus / pr.md
Created August 13, 2012 16:12
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@embs
embs / Rails 3.1 authentication from scratch.markdown
Created June 12, 2012 17:49
Authentication from Scratch with Rails 3.2.5

Authentication from Scratch with Rails 3.2.5

Rails 3.1 gives us a really easy way to authenticate users in our app: http_basic_authenticate_with. Using it, all we need to do is create a model for the user (certainly, User model :P) with an attribute called password_digest and some views feature for login and register users. After all, let's relax and let Rails do the hard work.

What we'll need

Gemfile

gem 'bcrypt-ruby', '~> 3.0.0'

Model

First at all, an User model which we can generate by following: rails g model user email:string password_digest:string and then add the following methodo call to generated class: has_secure_password

@mrdanadams
mrdanadams / application.js
Created March 28, 2012 20:41
Updating a DIV with partials after remote AJAX form submit in Rails 3
$(function() {
/* Convenience for forms or links that return HTML from a remote ajax call.
The returned markup will be inserted into the element id specified.
*/
$('form[data-update-target]').live('ajax:success', function(evt, data) {
var target = $(this).data('update-target');
$('#' + target).html(data);
});
});
@senko
senko / onchange.sh
Last active July 14, 2023 07:54
OnChange - Watch current directory and execute a command if anything in it changes
#!/bin/bash
#
# Watch current directory (recursively) for file changes, and execute
# a command when a file or directory is created, modified or deleted.
#
# Written by: Senko Rasic <senko.rasic@dobarkod.hr>
#
# Requires Linux, bash and inotifywait (from inotify-tools package).
#
# To avoid executing the command multiple times when a sequence of
@searls
searls / maven-git-flow.sh
Created June 24, 2011 00:25
My approximation of nvie's git flow when using maven-release-plugin to cut releases. - http://nvie.com/posts/a-successful-git-branching-model/
# How to perform a release with git & maven following the git flow conventions
# ----------------------------------------------------------------------------
# Finding the next version: you can see the next version by looking at the
# version element in "pom.xml" and lopping off "-SNAPSHOT". To illustrate,
# if the pom's version read "0.0.2-SNAPSHOT", the following instructions would
# perform the release for version "0.0.2" and increment the development version
# of each project to "0.0.3-SNAPSHOT".
# branch from develop to a new release branch
git checkout develop
@tyvsmith
tyvsmith / Setting.rb
Created June 5, 2011 20:42
Dynamic changes to schedule.rb for Whenever gem
class Setting < ActiveRecord::Base
validates_uniqueness_of :var
validates_presence_of :value
after_save :send_cron_later
#Setting.for(:display).set=(value)
def self.for(var)
find_or_create_by_var(var)