Skip to content

Instantly share code, notes, and snippets.

@ZenCocoon
ZenCocoon / gist:724366
Created December 1, 2010 22:36
Handling French date format in Ruby
## Try 1
# How could I get the following working nicely
Date.strptime("Ven 13 Mai. 2011, 16h00", "%a %d %b %Y, %Hh%M")
# I've tried to update Date::ABBR_DAYNAMES as follow
I18n.locale = :fr
Date::ABBR_DAYNAMES = I18n.t('date.abbr_day_names')
Date::ABBR_MONTHNAMES = I18n.t('date.abbr_month_names')
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("BookingSyncCalendarWidget",[],t):"object"==typeof exports?exports.BookingSyncCalendarWidget=t():e.BookingSyncCalendarWidget=t()}(this,function(){return function(e){function t(o){if(n[o])return n[o].exports;var i=n[o]={i:o,l:!1,exports:{}};return e[o].call(i.exports,i,i.exports,t),i.l=!0,i.exports}var n={};return t.m=e,t.c=n,t.i=function(e){return e},t.d=function(e,t,n){Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="/assets/",t(t.s=13)}([function(e,t,n){"use strict";function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}n.d(t,"g",function(){return d}),n.d(t,"n",function(){return u}),n.d(t,"l",function(){return g}),n.d(t,"c",function(){return h})
@ZenCocoon
ZenCocoon / invite_slack_user_everywhere.rb
Created January 28, 2017 01:47
Invite a Slack user to every non archived channels and groups
require "slack-ruby-client"
token = ...
user_name = ...
Slack.configure do |config|
config.token = token
end
client = Slack::Web::Client.new
@ZenCocoon
ZenCocoon / default.rb
Last active January 11, 2017 14:20
Whenever Chef Recipe on EY AppCloud
#
# Cookbook Name:: whenever
# Recipe:: default
#
ey_cloud_report "whenever" do
message "starting whenever recipe"
end
if node[:instance_role] == 'solo' ||
(node[:utility_instances].length > 0 && node[:utility_instances][0][:name] == node[:name]) ||
@ZenCocoon
ZenCocoon / _menu.liquid
Last active June 1, 2016 11:19
Handle sub-submenus with BookingSync generated websites
Replace:
``` liquid
<li><a href="{{ subitem.url }}">{{ subitem.title }}</a></li>
```
By:
``` liquid
@ZenCocoon
ZenCocoon / huboard-condensed-issues.css
Created January 13, 2016 05:56
Condensed HuBoard style
// Currently used with the bookmarklet http://www.paulirish.com/2008/bookmarklet-inject-new-css-rules/
.card { padding: 0 0 0 4px; margin-bottom: 0; border-bottom: 0 }
.card .title {
font-size: 12px;
line-height: 14px;
}
.card .hb-avatar-tooltip, .card .number { display: none; }
$.fn.extend
myplugin: (options) ->
self = $.fn.myplugin
opts = $.extend {}, self.default_options, options
$(this).each (i, el) ->
self.init el, opts
self.log el if opts.log
$.extend $.fn.myplugin,
default_options:
#
# Cookbook Name:: env_vars
# Recipe:: default
#
if ['solo', 'app', 'app_master', 'util'].include?(node[:instance_role])
execute "reload-nginx" do
action :nothing
command "/etc/init.d/nginx reload"
@ZenCocoon
ZenCocoon / gist:6180529
Created August 8, 2013 01:01
Test controller with file upload
describe "POST to #create" do
# Will use the file located at rspec/fixtures/files/test-document.pdf
let(:attachement) { fixture_file_upload('/files/test-document.pdf', "text/pdf") }
before do
post :create, attachment: {title: "Attachment Title", attachment: file_attachment}
end
it {should redirect_to some_path }
end
require 'benchmark'
require 'nokogiri'
n = 50000
Benchmark.bm do |x|
x.report { doc = Nokogiri::HTML::DocumentFragment.parse("<p>Foo Bar</p> <p>bar bar bar</p> <p>bla</p>") ; doc.children.map{|node| node.to_s.strip}.compact.join }
x.report { doc = Nokogiri::HTML::DocumentFragment.parse("<p>Foo Bar</p> <p>bar bar bar</p> <p>bla</p>") ; doc.children.each { |node| next_node = node.next_sibling ; next_node.remove if next_node && next_node.text.strip == '' } }
x.report { doc = Nokogiri::HTML("<p>Foo Bar</p> <p>bar bar bar</p> <p>bla</p>") ; doc.search('p').each { |node| next_node = node.next_sibling ; next_node.remove if next_node && next_node.text.strip == '' } }
end