Skip to content

Instantly share code, notes, and snippets.

@maephisto
maephisto / Javascript ISO country code to country name conversion
Last active November 3, 2023 21:05
ISO 3166-1 alpha-2 country code to country name conversion with a simple Javascript implementation, an array and a function.
var isoCountries = {
'AF' : 'Afghanistan',
'AX' : 'Aland Islands',
'AL' : 'Albania',
'DZ' : 'Algeria',
'AS' : 'American Samoa',
'AD' : 'Andorra',
'AO' : 'Angola',
'AI' : 'Anguilla',
'AQ' : 'Antarctica',
@maephisto
maephisto / Bohemian Rhapsody in Javascript
Created May 20, 2015 10:14
Bohemian Rhapsody in Javascript
try {
assert(Life.isReal);
assert(Life.isFantasy);
} catch (LandSlideException ex) {
while(!Reality.isEscapable) {
self.eyes.forEach(function(eye) {
eye
.open()
.lookTo(Sky)
.see();
@maephisto
maephisto / AWS base64 image upload
Created June 16, 2014 11:30
Node upload base64 image data to AWS
var config = {
"aws" : {
"bucket": "...",
"domain" : "...",
"prefix" : "..",
"path": "my/test/",
"credentials" : {
"accessKeyId": "...",
"secretAccessKey": "..."
}
@maephisto
maephisto / module-README.md
Last active June 26, 2018 07:10
Module README template

Package name

Short description about the intended purpose of the package.E.g. This package offers a way to create and manage dragons.

Usage

How does one use this package? Provide examples. E.g. Package can be installed from NPM registry via npm i dragon

Package API

Documents the public API fo the module. E.g.

@maephisto
maephisto / expressive-console.js
Created August 28, 2017 14:29
A expressive layer added on top of Javascript's `console` to better illustrate what that voice in your mind is saying.
var _log = console.log;
var _error = console.error;
var _warning = console.warn;
console.error = function (errMessage) {
errMessage = 'Ooooh 💩💩💩 : ' + errMessage;
_error.apply(console, arguments);
};
console.log = function (logMessage) {
@maephisto
maephisto / PayloadQParserPlugin.java
Last active November 24, 2016 12:56
Simple Payload Query Parser (Solr/Lucene)
import org.apache.commons.lang.StringUtils;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.BooleanClause.Occur;
import org.apache.lucene.search.payloads.AveragePayloadFunction;
import org.apache.lucene.search.payloads.PayloadTermQuery;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.request.SolrQueryRequest;
@maephisto
maephisto / documents.xml
Created January 15, 2014 10:02
documents added
<add>
<doc>
<field name="id">1</field>
<field name="title">Doc one</field>
<field name="payloads">testone|10.4 testtwo|30.2 testthree|5.6</field>
<field name="text">I testone, you testtwo, they testthree</field>
</doc>
<doc>
<field name="id">2</field>
<field name="title">Doc two</field>
@maephisto
maephisto / response.json
Created January 15, 2014 09:56
Solr response for http://localhost:8983/solr/collection1/pds-search?q=payloads:testone&wt=json&indent=true&debugQuery=true
{
"responseHeader":{
"status":0,
"QTime":2},
"response":{"numFound":4,"start":0,"docs":[
{
"id":"1",
"title":["Doc one"],
"payloads":"testone|10.4 testtwo|30.2 testthree|5.6",
"_version_":1457289004134170624},
@maephisto
maephisto / solrconfig.xml
Last active January 3, 2016 07:59
Changes that need to be made to solrconfig.xml
<lib path="../../lib/solr-payloads-plugin.jar"/>
<!-- Request Handler to do payload queries -->
<queryParser name="payloadQueryParser" class="com.custom.solr.PayloadQParserPlugin"/>
<requestHandler name="/pds-search" class="solr.SearchHandler">
<lst name="defaults">
<str name="defType">payloadQueryParser</str>
</lst>
</requestHandler>
@maephisto
maephisto / schema.xml
Last active January 3, 2016 07:59
Changes that need to be made to schema.xml
<similarity class="com.custom.solr.CustomSolrSimilarity" />