Skip to content

Instantly share code, notes, and snippets.

View ramhoj's full-sized avatar

Nicklas Ramhöj Holtryd ramhoj

  • Gothenburg, Sweden
  • 14:56 (UTC +02:00)
View GitHub Profile
module XPath
extend self
def self.generate
yield(Expression::Self.new)
end
class Expression
include XPath
@ramhoj
ramhoj / overload_jquery_load.coffee
Created November 30, 2010 14:47
overload_jquery_load.coffee
describe 'TaskNavigator', ->
template 'task_panel.html'
beforeEach ->
@taskNavigator = new TaskNavigator()
@taskNavigator.showSection.load = =>
$(".show").html(Evergreen.templates["task_show.html"])
@taskNavigator.bindEvents()
@ramhoj
ramhoj / application.js
Created February 29, 2012 16:31
Date picker defaults
var occurrences = $(".occurrences");
if(occurrences.find(".error").length > 0) {
occurrences.find("a.add").hide();
} else {
occurrences.find(".fields:not(:has(input[type='checkbox'])):not(:first)").hide();
occurrences.find("a.add").click(function(e) {
var prevOccurrence = occurrences.find(".fields:not(:hidden):last");
var nextOccurrence = occurrences.find(".fields:hidden:first");
var inputs = "input[type='text'], select";
@ramhoj
ramhoj / parent_registration_validator.rb
Created March 5, 2012 15:54
Custom validation objects
class ParentRegistartionValidator < ActiveModel::Validator
def validate(record)
record.errors.add(:weight, :blank) unless record.weight.present?
...
end
end
@ramhoj
ramhoj / workaround.rb
Created March 23, 2012 13:04
Time.zone.parse bug
# Use
DateTime.parse("2012-03-25 03:29").in_time_zone(Time.zone)
# Instead of
Time.zone.parse("2012-03-25 03:29")
# Until the pull request https://github.com/jarkko/rails/commit/bb4a1d68f6db8bf99d2b6e21eee72a19d494dee0 has been pulled into Rails.
@ramhoj
ramhoj / verify_push.exs
Created April 11, 2016 08:33
verify_push.exs
# Run with iex -S mix run script/verify
defmodule Pitch.VerifyPush do
@valid_tokens [
"7a61a279e0a35396d08ce13131fa6e2278a404f53683f17a16e1d6566223c712" # add more here
]
@number_of_bad_tokens 10
@pool :my_pool_name
@ramhoj
ramhoj / s3_read_only_policy.json
Last active August 16, 2017 17:42
AWS IAM S3 read/write only policy
{
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetBucketLocation",
"s3:GetObject",
"s3:ListBucket"
],
"Resource": [
require "aws-sdk"
require "pry"
filename = File.expand_path("./deploy/video.rb", File.dirname(__FILE__))
config_file = File.open(filename, "w")
client = Aws::EC2::Client.new(
region: "eu-west-1",
access_key_id: "access_key_id",
secret_access_key: "secret_access_key"
@ramhoj
ramhoj / phoenix-generate.sh
Created July 5, 2016 08:21
phoenix-generate.sh
brew install erlang
brew install elixir
git clone https://github.com/phoenixframework/phoenix.git
cd phoenix
mix do deps.get, compile
mix phoenix.new ../my_app
cd ../my_app
mix do deps.get, compile
mix phoenix.server