Skip to content

Instantly share code, notes, and snippets.

View kardeiz's full-sized avatar

Jacob Brown kardeiz

View GitHub Profile
@kardeiz
kardeiz / strip_margin.rs
Created April 12, 2016 16:04
Rust stripMargin
pub trait StripMargin {
fn strip_margin(self) -> String;
}
impl StripMargin for &'static str {
fn strip_margin(self) -> String {
let mut out = Vec::new();
for l in self.lines()
.filter(|x| !x.is_empty() ) {
for s in l.splitn(2, '|').nth(1) {
@kardeiz
kardeiz / q01.rs
Last active August 29, 2015 14:25
proj-eul-rs
fn main() {
let mut acc = 0;
for i in (0..1000) {
if (i % 5 == 0) || (i % 3 == 0) {
acc += i;
}
}
println!("{}", acc);
}
extern crate glob;
extern crate regex;
extern crate csv;
use std::vec::Vec;
use std::env;
use glob::glob;
use std::path::{Path, PathBuf};
use std::io::prelude::*;
@kardeiz
kardeiz / Capfile
Last active August 29, 2015 14:24
DSpace deployment with Capistrano 3
gem 'capistrano', '~> 3.4.0'
require File.expand_path('../.env.rb', __FILE__)
require 'capistrano/all'
require 'capistrano/deploy'
include Capistrano::DSL
set :application, ENV['app_name']
@kardeiz
kardeiz / gist:682714d2a1fa02872a96
Created April 14, 2015 15:05
Difference bw `rails new myapp --skip-sprockets` and `rails new myapp` for Rails 4.2.1
diff -r tmp3/myapp/config/application.rb tmp2/myapp/config/application.rb
3,12c3
< require "rails"
< # Pick the frameworks you want:
< require "active_model/railtie"
< require "active_job/railtie"
< require "active_record/railtie"
< require "action_controller/railtie"
< require "action_mailer/railtie"
< require "action_view/railtie"
@kardeiz
kardeiz / gist:d80bc301e67cc87d1eb4
Last active August 29, 2015 14:19
Difference bw `rails new myapp -O` and `rails new myapp` for Rails 4.2.1
diff -r tmp1/myapp/config/application.rb tmp2/myapp/config/application.rb
3,12c3
< require "rails"
< # Pick the frameworks you want:
< require "active_model/railtie"
< require "active_job/railtie"
< # require "active_record/railtie"
< require "action_controller/railtie"
< require "action_mailer/railtie"
< require "action_view/railtie"
@kardeiz
kardeiz / gist:c8ab990614dbbcb31213
Created November 11, 2014 16:33
script to output DSpace resource policy info
#!/bin/env jruby
require 'csv'
DSPACE_CFG = 'path to your dspace.cfg'
DSPACE_DIR = File.expand_path('../..', DSPACE_CFG)
DSPACE_JARS = Dir[File.join(DSPACE_DIR, 'lib/*.jar')]
ADMIN_EMAIL = 'your admin email'
OUTPUT = '/tmp/rp.csv'
@kardeiz
kardeiz / saxon-for-dspace.md
Last active June 28, 2016 18:46
Using Saxon with Cocoon XSLT for DSpace

Using Saxon with Cocoon XSLT for DSpace

Create an xconf file at [dspace-src]/dspace/modules/xmlui/src/main/resources/META-INF/cocoon/avalon/cocoon-core-saxon-xslt.xconf and add the following lines:

<?xml version="1.0" encoding="UTF-8"?>
<components>
  <component role="org.apache.excalibur.xml.xslt.XSLTProcessor/saxon"
 class="org.apache.cocoon.components.xslt.TraxProcessor"&gt;
Import-Module PSTerminalServices
Function OctetToHours ($Octet)
{
# Function to convert Octet value (byte array) into binary string
# representing logonHours attribute. The 168 bits represent 24 hours
# per day for 7 days, Sunday through Saturday. The values are converted
# into local time. If the bit is "1", the user is allowed to logon
# during that hour. If the bit is "0", the user is not allowed to logon.
$Bias = (Get-ItemProperty -Path HKLM:\System\CurrentControlSet\Control\TimeZoneInformation).Bias
class Description < ActiveRecord::Base
belongs_to :user
belongs_to :product
belongs_to :document
# attr_accessible :title, :body
validate :check_limit
def check_limit
if self.class.where(:user_id => self.user_id).count >= 1