Skip to content

Instantly share code, notes, and snippets.

View frimik's full-sized avatar

Mikael Fridh frimik

  • Electronic Arts / DICE
  • Uppsala, Sweden
View GitHub Profile
@bowsersenior
bowsersenior / stooge_loader.rb
Created May 18, 2011 23:18
A demo of YAML anchors, references and nested values
require 'rubygems'
require 'yaml'
# A demonstration of YAML anchors, references and handling of nested values
# For more info, see:
# http://atechie.net/2009/07/merging-hashes-in-yaml-conf-files/
stooges = YAML::load( File.read('stooges.yml') )
# => {
# "default" => {
@amyreese
amyreese / znc-query-buffering.patch
Created September 9, 2011 14:02
Query Buffering Patch for ZNC
This patch make ZNC query buffering behave the way I like, as I use
multiple clients and still want the query buffer to be filled and replayed
for the newly connecting client.
diff -rup znc-0.074/IRCSock.cpp znc/IRCSock.cpp
--- znc-0.074/IRCSock.cpp 2009-06-29 13:26:19 +0200
+++ znc/IRCSock.cpp 2009-08-26 11:30:56 +0200
@@ -724,21 +724,14 @@ bool CIRCSock::OnGeneralCTCP(CNick& Nick
bool CIRCSock::OnPrivNotice(CNick& Nick, CString& sMessage) {
MODULECALL(OnPrivNotice(Nick, sMessage), m_pUser, NULL, return true);
@fxtentacle
fxtentacle / agent.conf
Created October 31, 2011 20:44
Hajo's logstash config
input {
exec {
type => "dstat"
command => "dstat -cdngypms --nocolor 1 0"
interval => 13
}
exec {
type => "apache-benchmark"
@crazed
crazed / ip.rb
Created December 2, 2011 21:42
useful facter plugins
if File::exists?("/sbin/ip")
Facter.add('gateway') do
setcode do
`/sbin/ip route show`.match(/^default.*/)[0].match(/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/)[0]
end
end
end
@vStone
vStone / params.pp
Created January 19, 2012 15:25
Example / Trial use case for 'dynamic' module incorp.
# === Actions:
#
# === Requires:
#
# === Sample Usage:
#
class passenger::params (
$packages = undef,
$configpath = undef,
$version = undef,
@jordansissel
jordansissel / README.md
Created February 19, 2012 06:30
Reading RPMs

Something in RPM changed between RHEL5 and RHEL6.

I can read RPMs for CentOS5 and earlier, but in EL6, the signature header is longer than expected by exactly 4 bytes. I have also observed some normal header (non signature) sections being longer than expected by 16 bytes. It is quite confusing.

If you have insight, please let me know here.

@leinaddm
leinaddm / dell_soap_check.py
Created February 23, 2012 14:18
dell warranty check
#!/usr/bin/python
# Daniel De Marco - ddm@didiemme.net - 2012-02-23
# suds from https://fedorahosted.org/suds/
import suds
import sys
def get_warr(svctag):
#! /bin/sh
#
USER="admin"
PASS="changeme"
FOREMAN_URL="https://foreman"
FQDN=$1
CHANGED_ATTRIBUTE="host[environment_id]=2"
curl -H "Accept:application/json" -X PUT \
-k -u $USER:$PASS \

Proposal for Improving Mass Assignment

For a while, I have felt that the following is the correct way to improve the mass assignment problem without increasing the burden on new users. Now that the problem with the Rails default has been brought up again, it's a good time to revisit it.

Sign Allowed Fields

When creating a form with form_for, include a signed token including all of the fields that were created at form creation time. Only these fields are allowed.

To allow new known fields to be added via JS, we could add:

@rafaelp
rafaelp / gist:1976687
Created March 5, 2012 04:55
A solution to a more obscure problem related to the "vulnerability" of mass assignment:
# account.rb
class Account < ActiveRecord::Base
has_many :users
has_many :services
end
# user.rb
class User < ActiveRecord::Base
belongs_to :account
end