In programming languages, literals are textual representations of values in the source code. This is a syntactical concept.
Some examples:
7 # integer literal
In programming languages, literals are textual representations of values in the source code. This is a syntactical concept.
Some examples:
7 # integer literal
A memory-saving ActiveRecord setting has been used by just one application ever, according to GitHub | |
There's a common performance problem in many Rails background jobs. | |
Background jobs often do operations across large sets of data. Basically, they do silly things like User.all.each(&:send_daily_newsletter). | |
So, there's a problem with that query. In development and test environments, User.all will probably return a few rows, maybe a dozen at most. Most developers have extremely limited seed data on their local machines. | |
In production, however, User.all will probably return quite a few rows. Depending on the app you work on, maybe a few hundred thousand. | |
There's a tiiiiiny issue with a result set that returns 100,000 rows, and it's not just that the SQL query will take a long time to return. It will have irreversible effects on your Ruby app too! |
# assuming Model is your model and options is a json/jsonb column. | |
# This uses the Postgres json append || operator. | |
# And wraps the option inside an array. | |
# producing [{},{}] multiple hashes inside a top level json array. | |
# It is very important that the hash is [{}] NOT {} as not having the array on the | |
# outside will cause the hash to replace the contents instead of appending to them. | |
new_option = [{ | |
name: option_name, |
"use strict"; | |
/*use in config.xml <hook type="after_platform_add" src="../path/to/cordova-ios-disable-push.js"/>*/ | |
var fs = require("fs"); | |
var path = require("path"); | |
var COMMENT_KEY = /_comment$/; | |
function nonComments(obj) { | |
var newObj = {}; | |
Object.keys(obj).forEach(function(key) { | |
if (!COMMENT_KEY.test(key)) { |
"use strict"; | |
/*use in config.xml <hook type="after_platform_add" src="../path/to/cordova-ios-disable-push.js"/>*/ | |
var fs = require("fs"); | |
var path = require("path"); | |
var COMMENT_KEY = /_comment$/; | |
function nonComments(obj) { | |
var newObj = {}; | |
Object.keys(obj).forEach(function(key) { | |
if (!COMMENT_KEY.test(key)) { |
#Laravel 5 Simple ACL manager
Protect your routes with user roles. Simply add a 'role_id' to the User model, install the roles table and seed if you need some example roles to get going.
If the user has a 'Root' role, then they can perform any actions.
Simply copy the files across into the appropriate directories, and register the middleware in App\Http\Kernel.php
<?php | |
/** | |
* Apply a different tax rate based on the user role. | |
*/ | |
function wc_diff_rate_for_user( $tax_class, $product ) { | |
if ( is_user_logged_in() && current_user_can( 'administrator' ) ) { | |
$tax_class = 'Zero Rate'; | |
} | |
return $tax_class; |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
#!/usr/bin/env bash | |
set -u | |
set -e | |
export GIT_WORK_TREE="/var/www/example.com" | |
export NODE_VERSION="0.10" | |
echo "--> Checking out..." | |
git checkout -f |
This is just a jotting of notes on how to embed Faye into a single Rails process. Makes it nice to do simple real time things without the need for a separate Faye server/process.
Also uses Faye Redis to work across load balanced Rails apps.
You also need to copy the compiled javascript into vendor/assets/javascripts
and include into application.js
manifest.
Ignore the numbers in the file names... just used to add order to the Gist.
This uses the faye/faye Github repo at edc5b42f6560d31eae61caf00f6765a90e1818d1
since I wanted to use with the Puma rack server and that is only available in the master branch (until Faye 1.0)