Skip to content

Instantly share code, notes, and snippets.

@stevehanson
stevehanson / es-attach.py
Last active February 13, 2017 11:39
Example using the elasticsearch-mapper-attachments (https://github.com/elasticsearch/elasticsearch-mapper-attachments) plugin to index files (pdf, docx, html, etc). Usage with "python es-attach.py my-filename. Credit to Lucas Vlcek's similar Gist using Perl - https://gist.github.com/lukas-vlcek/1075067.
import os
import sys
# constants, configure to match your environment
HOST = 'http://localhost:9200'
INDEX = 'test'
TYPE = 'attachment'
TMP_FILE_NAME = 'tmp.json'
@stevehanson
stevehanson / es-attach-full.py
Last active November 22, 2020 21:22
Interactive Python script to recursively index files in directory tree to elasticSearch using the elasticsearch-mapper-attachments (https://github.com/elasticsearch/elasticsearch-mapper-attachments) plugin to index files (pdf, docx, html, etc).
import os
import sys
# constants, configure to match your environment
HOST = 'http://localhost:9200'
INDEX = 'test'
TYPE = 'attachment'
TMP_FILE_NAME = 'tmp.json'
# for supported formats, see apache tika - http://tika.apache.org/1.4/formats.html
INDEX_FILE_TYPES = ['html','pdf', 'doc', 'docx', 'xls', 'xlsx', 'xml']
@stevehanson
stevehanson / AppMain.java
Last active December 28, 2015 20:29
Spring simple app. Used for tutorial session.
package com.tutorial;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class AppMain {
public static void main(String[] args) {
ApplicationContext cxt = new ClassPathXmlApplicationContext("applicationContext.xml");
GreetService svc = cxt.getBean(GreetService.class);
@stevehanson
stevehanson / MainController.java
Created January 10, 2014 15:16
Spring MVC Example
// com.tutorial.MainController.java
package com.tutorial;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
@stevehanson
stevehanson / Email.java
Created May 8, 2014 14:37
Mailgun Example - Java
package com.abc.model;
import java.util.List;
public class Email {
private String from;
private List<String> to;
private List<String> cc;
private List<String> bcc;
@stevehanson
stevehanson / transparent_bg.scss
Last active September 27, 2018 19:50
Mixin to achieve background-image with overlay
// see http://stackoverflow.com/questions/4183948/css-set-background-image-with-opacity
@mixin transparent_bg($bg_image, $overlay_opacity: "", $overlay_color: "") {
background: -webkit-linear-gradient(left, rgba($overlay_color, $overlay_opacity), rgba($overlay_color, $overlay_opacity)), url($bg_image) no-repeat;
background: -moz-linear-gradient(left, rgba($overlay_color, $overlay_opacity), rgba($overlay_color, $overlay_opacity)), url($bg_image) no-repeat;
background: -o-linear-gradient(left, rgba($overlay_color, $overlay_opacity), rgba($overlay_color, $overlay_opacity)), url($bg_image) no-repeat;
background: -ms-linear-gradient(left, rgba($overlay_color, $overlay_opacity), rgba($overlay_color, $overlay_opacity)), url($bg_image) no-repeat;
}
@stevehanson
stevehanson / Gemfile
Last active February 4, 2021 23:06
Rails – Simple Google Login
gem "omniauth"
gem "omniauth-google-oauth2"
@stevehanson
stevehanson / emblem_to_hbs.rb
Last active February 22, 2019 21:54
Convert all project Emblem files to handlebars
class EmblemToHbs
def convert
Dir.glob("**/*.emblem").each do |file|
convert_file(file)
end
end
def convert_file(file)
`emblem2hbs #{file}`
File.delete(file)
@stevehanson
stevehanson / promises.js
Created August 7, 2015 19:55
RSVP.all Promises Example
let promises = [];
comments.forEach((comment) => {
promises.push(comment.save());
});
Ember.RSVP.all(promises).then((comments) => {
post.get('comments').addObjects(comments);
post.save();
});
import Ember from 'ember';
export default Ember.Component.extend({
listUpdated: 'listUpdated',
initSortable: function() {
var refreshed = false;
var _this = this;
this.$().sortable({