Skip to content

Instantly share code, notes, and snippets.

@maephisto
maephisto / CustomSolrSimilarity.java
Last active January 3, 2016 07:59
Simple Custom Similarity for Payloads (Solr/Lucene)
import org.apache.lucene.analysis.payloads.PayloadHelper;
import org.apache.lucene.search.similarities.DefaultSimilarity;
import org.apache.lucene.util.BytesRef;
public class CustomSolrSimilarity extends DefaultSimilarity {
@Override
public float scorePayload(int doc, int start, int end, BytesRef payload) {
if (payload != null) {
return PayloadHelper.decodeFloat(payload.bytes);;
@maephisto
maephisto / git-prepush-hook
Last active August 29, 2015 14:19
git prepush hook
#!/bin/sh
echo "\nLet me check if you can push this!"
echo "\nExecuting unit tests..."
testValidationResult=$(grunt test | grep "Done, without errors")
if [ "$testValidationResult" != "" ]; then
echo "\033[32mUnit tests execution passed. Wow, such tests, much green!\033[0m"
else
@maephisto
maephisto / DustJS Access Array By Index
Created March 6, 2015 10:18
How to access elements by index in DustJs
{#names}{@idx}
{@if cond="('{.}' == 0)"}
First is: {name}
{:else}
Other: {name}
{/if}
{/idx}{/names}
@maephisto
maephisto / git-pre-commit-hook validator
Last active August 29, 2015 14:14
Pre-commit hook doing a jshint and less before comitting.
#!/bin/sh
echo "\nLet me check if you can commit!"
jsFiles=$(git diff --cached --name-only --diff-filter=ACM | grep ".js$")
lessFiles=$(git diff --cached --name-only --diff-filter=ACM | grep ".less$")
if [ "$jsFiles" = "" ]; then
echo "\033[32mNo JavaScript files were modified.\033[0m"
if [ "$lessFiles" = "" ]; then
@maephisto
maephisto / solution.js
Created January 29, 2015 21:03
Trello Javascript challenge solution
// what we're working with
var characterList = 'acdegilmnoprstuw';
// what we're going for
var theHashWeWereLookingFor = 956446786872726;
var theMagicString = '';
//Now reverse engineer
while (theHashWeWereLookingFor > 7 ) {
var counter = 0;
@maephisto
maephisto / get languages spoken in a certain country (by country code)
Created February 28, 2014 14:38
This gist shows how to get languages spoken in a certain country (by country code)
var countryToLanguages = { AD: [ 'ca' ],
AE: [ 'ar', 'fa', 'en', 'hi', 'ur' ],
AF: [ 'fa', 'ps', 'uz', 'tk' ],
AG: [ 'en' ],
AI: [ 'en' ],
AL: [ 'sq', 'el' ],
AM: [ 'hy' ],
AO: [ 'pt' ],
AR: [ 'es', 'en', 'it', 'de', 'fr', 'gn' ],
AS: [ 'en', 'sm', 'to' ],