Skip to content

Instantly share code, notes, and snippets.

View XORwell's full-sized avatar
:octocat:
XORwell@github:~$ profile

Christian Nennemann XORwell

:octocat:
XORwell@github:~$ profile
View GitHub Profile
@XORwell
XORwell / simple_form_bootstrap.rb
Last active September 3, 2018 05:15
bootstrap 3 simple_form wrappers
# http://stackoverflow.com/a/18684021
# Bootstrap 3
inputs = %w[
CollectionSelectInput
DateTimeInput
FileInput
GroupedCollectionSelectInput
NumericInput
PasswordInput
RangeInput
-# prepend example #1 (content_tag)
= f.input :date, :input_html => { :class => 'datepicker' }, :wrapper => :prepend do
= f.input_field :date
= content_tag :span, :class => 'input-group-addon' do
= content_tag :span, nil, :class => 'glyphicon glyphicon-search'
-# prepend example #2 (haml tag)
= f.input :date, :input_html => { :class => 'datepicker' }, :wrapper => :prepend do
= f.input_field :date
%span.input-group-addon
@XORwell
XORwell / jquery_select_filter.js
Created October 11, 2013 07:50
filter select input and set the selected value
function set_select_selected(value){
$("#my_field > option").filter(function() {
return $(this).text() == value //the condition
}).prop('selected', true);
}
@XORwell
XORwell / monkeypatch_icecube_occurrence.rb
Created October 13, 2013 19:45
# Evolve IceCube Occurrence # Background: IceCubes ::all_occurrences returns Occurrence Objects # This patch makes it possible to store IceCube::Schedule#all_occurrences return value into Mongoid field type Array
class IceCube::Occurrence
def self.evolve(occurrence)
occurrence.to_time
end
end
@XORwell
XORwell / redirect_pages_back.rb
Created October 30, 2013 18:46
rails redirect some more pages back than redirect_to :back
#ApplicationController
after_action :set_pages
def set_pages
max_size = 5
session[:pages] = [] unless session[:pages]
session[:pages].shift while(session[:pages].size >= max_size)
session[:pages] << request.original_url
end
# ApplicationController
around_filter :global_request_logging
def global_request_logging
logger.tagged('USERAGENT'){ logger.info "#{request.headers['HTTP_USER_AGENT']}" }
begin
yield
ensure
logger.info "response_status: #{response.status}"
end
@XORwell
XORwell / active_ldap_extensions.rb
Last active December 28, 2015 05:29
ActiveLdap Extensions
# ActiveLdapExtensions
#
# @author Christian Nennemann
#
module ActiveLdapExtensions
extend ActiveSupport::Concern
module Time
# Convert the time to the FILETIME format, a 64-bit value representing the
# number of 100-nanosecond intervals since January 1, 1601 (UTC).
#!bin/bash
# Requirements: imagemagick, ghostscript, pdftk
#############################################
# create pdf for each png
#############################################
for image in *.png; do
filename="${image%%.*}".pdf
@XORwell
XORwell / net_http_digest_auth.rb
Created October 11, 2020 19:17 — forked from KINGSABRI/net_http_digest_auth.rb
HTTP Digest Auth for Ruby's net/http
# Support for http digest auth
# Discovered here: http://johan.bingodisk.com/public/code/net_digest_auth.rb
require 'digest/md5'
require 'net/http'
module Net
module HTTPHeader
@@nonce_count = -1
CNONCE = Digest::MD5.new("%x" % (Time.now.to_i + rand(65535))).hexdigest