Defining Eloquent model (will assume that DB table named is set as plural of class name and primary key named "id"):
class Shop extends Eloquent {}
Using custom table name
protected $table = 'my_shops';
#!/usr/bin/env bash | |
# This script prints out all of your Redis keys and their size in a human readable format | |
# Copyright 2013 Brent O'Connor | |
# License: http://www.apache.org/licenses/LICENSE-2.0 | |
human_size() { | |
awk -v sum="$1" ' BEGIN {hum[1024^3]="Gb"; hum[1024^2]="Mb"; hum[1024]="Kb"; for (x=1024^3; x>=1024; x/=1024) { if (sum>=x) { printf "%.2f %s\n",sum/x,hum[x]; break; } } if (sum<1024) print "1kb"; } ' | |
} |
/* | |
<a href="posts/2" data-method="delete"> <---- We want to send an HTTP DELETE request | |
- Or, request confirmation in the process - | |
<a href="posts/2" data-method="delete" data-confirm="Are you sure?"> | |
*/ | |
(function() { |
This will allow you to use devise's TokenAuthenticatable strategy while passing your :auth_token in using HTTP Authorization headers instead of params.
You can check it out using
curl -H "Authorization: Token token=XXXXXX, option=1" -vv http://railsapp.dev/api/v1/endpoint.json
It should properly authenticate using the token as well as set request.env['token.options']
to {"options" => "1"}
.
var MyModel = Backbone.Model.extend({ | |
someMethod: function(opts) { | |
var url = this.url() + '/someMethod', | |
// note that these are just $.ajax() options | |
options = { | |
url: url, | |
type: 'POST' | |
}; | |
// add any additional options, e.g. a "success" callback or data |
var express = require('express'), | |
httpProxy = require('http-proxy'), | |
app = express(); | |
var proxy = new httpProxy.RoutingProxy(); | |
function apiProxy(host, port) { | |
return function(req, res, next) { | |
if(req.url.match(new RegExp('^\/api\/'))) { | |
proxy.proxyRequest(req, res, {host: host, port: port}); |
/* | |
jquery.draghover.js | |
Emulates draghover event by tracking | |
dragenter / dragleave events of element + children. | |
https://gist.github.com/gists/3794126 | |
http://stackoverflow.com/a/10310815/4196 |
Create an .htaccess file in the webroot:
AuthUserFile /app/www/.htpasswd
AuthType Basic
AuthName "Restricted Access"
Require valid-user
Create a .htpasswd file:
htpasswd -c /app/www/.htpasswd [username]
# 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 |