Skip to content

Instantly share code, notes, and snippets.

View zealot128's full-sized avatar

Stefan Wienert zealot128

View GitHub Profile
@zealot128
zealot128 / imap-stats.rb
Created May 20, 2012 20:05
Imap mail statistic with Ruby
require "net/imap"
require "progressbar"
require "active_support/all" # sort_by!
class Array
def histogram ; self.sort.inject({}){|a,x|a[x]=a[x].to_i+1;a} ; end
end
server = "mailserver.com"
username = "mail@mailserver.com"
@zealot128
zealot128 / solution.rb
Last active December 10, 2015 21:18
Solution for a job challenge by barzahlen.de
raise "UseNewerRubyCauseHazPermutations" if RUBY_VERSION < "1.9.3"
%w["d3Vv", "dG5h", "QGVt"].permutation.to_a.map(&:join).each do |middle|
puts Base64.decode64( "ZWQubmVsaGF6cmFi" + middle + "eQ==").reverse
end
@zealot128
zealot128 / convenience_findable.rb
Last active December 14, 2015 06:09
Convenience Finder for ActiveRecord Models Finding models with a attribute "name": imagine having Domains with names: "ITsax.de", "ITmitte.de" Domain["its"] Domain["itsax.de"] Domain.itsax All gives the Domain named "ITsax.de
# Super easy finder fuer models mit einem Attribut :name
#
# Erweitert:
#
# Domain.itsax
# Domain.itmitte
#
# User.pludoni
#
# User["plu"] -> pludoni
@zealot128
zealot128 / console.js
Last active December 17, 2015 00:29
Coursera - initiate download for all videos of a whole course - Paste into debug console
// wait 8 seconds between each download
waittime = 8000
// only download links that are visible right now -> Fold old lectures
only_visible = true
ls=$.map($('.icon-download-alt'),function(a,e){link=$(a).parent();link.attr("target", "_blank");return link});if(only_visible) ls=ls.filter(function(a){return a.is(":visible")});function ex(){ls.shift().find("i").click();if(ls.length>0)setTimeout(ex, waittime)};ex()
@zealot128
zealot128 / rails.vim
Created May 29, 2013 20:43
some rails.vim projections for the new projections feature
let g:rails_projections = {
\ "config/projections.json": {
\ "command": "projections"
\ },
\ "app/services/*.rb": {
\ "command": "service",
\ "affinity": "model",
\ "test": "spec/services/%s_spec.rb",
\ "related": "app/models/%s.rb",
\ "template": "class %S\n\n def run\n end\nend"
@zealot128
zealot128 / _two_click.html.haml
Created August 29, 2013 08:16
Rails: Two Click Image helper for easy dropin daily refreshed Facebook/Twitter/SocialPlugins as static images (to comply with German data protection standards). Needs wkhtmltoimage installed on server.
.two-click{data: { iframe: url, height: height, width: width} }
= link_to url, title: t("two-click.info"), target: "_blank", rel: "nofollow" do
= image_tag image_url, class: "two-click-img"
@zealot128
zealot128 / gist:6485657
Created September 8, 2013 15:32
Wicked_pdf/wkhtml webfonts usage. (Rails) just convert ttf-font to base64
@font-face {
font-family: "HelveticaNeue";
src: url(data:font/truetype;charset=utf-8;base64,#{Base64.encode64(File.read("app/assets/fonts/helveticaneue-light-webfont.ttf")).gsub("\n","")});
font-weight: normal;
font-style: normal;
}
body, h1, h2, h3 {
# normal regex with unnamed groups -> JS/PHP,Pearl
/(\/v\/|\/embed\/|watch?.*v=)([A-Za-z0-9\-_]*)|youtu\.be\/([A-Za-z0-9\-_]*)/
# normal regex with named groups
m = /(\/v\/|\/embed\/|watch?.*v=)(?<id>[A-Za-z0-9\-_]*)|youtu\.be\/(?<id>[A-Za-z0-9\-_]*)/
m.match("http://youtu.be/fat9235")[:id]
# -> fat9235
@zealot128
zealot128 / ole.rb
Created September 18, 2013 15:39
OLE access binary extraction of PDF
ole_bin = File.open("...","rb")
# just look for PDF Marker and EOF Marker
pdf_bin = ole_bin[/(%PDF-.*%%EOF\r?\n)/m,1]
@zealot128
zealot128 / ansible.vim
Last active December 24, 2015 18:19
vim ansible specific yaml highlightings
augroup ansible_yaml
autocmd!
au BufRead playbook.yml,roles/*yml,ansible*yml call SetAnsibleOpts()
augroup END
function SetAnsibleOpts()
syntax match yamlInterpolate '$\w\+\|{{[^}]\+}}'
syntax match yamlInterpolate '$\w\+\|{{[^}]\+}}' contained containedin=yamlString
syntax match yamlConstant '\(with_items\|when\|name\|notify\|ignore_errors\|changed_when\|register\|with_password\):'
endfunction