Skip to content

Instantly share code, notes, and snippets.

View elvanja's full-sized avatar

Vanja Radovanović elvanja

View GitHub Profile
@elvanja
elvanja / boolean_query.ex
Last active November 27, 2023 14:45
Boolean query lexer (not AST unfortunately)
defmodule BooleanQuery do
use Ecto.Type
import Gettext
def type, do: :string
@operator_expressions %{
"AND" => {:operator, "+"},
"UND" => {:operator, "+"},
50 4f 53 54 20 2f 61 70 P O S T / a p
69 2f 61 70 70 6c 69 63 i / a p p l i c
61 74 69 6f 6e 73 2f 62 a t i o n s / b
34 30 62 64 36 66 61 2d 4 0 b d 6 f a -
36 39 33 63 2d 34 39 34 6 9 3 c - 4 9 4
36 2d 39 63 38 35 2d 34 6 - 9 c 8 5 - 4
62 61 66 66 39 63 61 62 b a f f 9 c a b
36 63 63 2f 64 6f 63 75 6 c c / d o c u
6d 65 6e 74 73 20 48 54 m e n t s H T
54 50 2f 31 2e 31 0d 0a T P / 1 . 1 . .
@elvanja
elvanja / pom.xml
Created January 20, 2013 16:34
Maven project definition for NodeJS deployable project.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.acme.test</groupId>
<artifactId>nodejs-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>nodejs-test</name>
<description>NodeJS Test Project</description>
<packaging>jar</packaging>
@elvanja
elvanja / build_elastic_search_mapping.ex
Created September 10, 2020 13:16
Build Elasticsearch mapping schema from given Elixir struct's typespec
defmodule DataKiosk.Utils.BuildElasticsearchMapping do
@moduledoc """
██╗ ██╗███████╗██████╗ ███████╗ ██████╗ ███████╗ ██████╗ ██████╗ █████╗ ██████╗ ██████╗ ███╗ ██╗███████╗
██║ ██║██╔════╝██╔══██╗██╔════╝ ██╔══██╗██╔════╝ ██╔══██╗██╔══██╗██╔══██╗██╔════╝ ██╔═══██╗████╗ ██║██╔════╝
███████║█████╗ ██████╔╝█████╗ ██████╔╝█████╗ ██║ ██║██████╔╝███████║██║ ███╗██║ ██║██╔██╗ ██║███████╗
██╔══██║██╔══╝ ██╔══██╗██╔══╝ ██╔══██╗██╔══╝ ██║ ██║██╔══██╗██╔══██║██║ ██║██║ ██║██║╚██╗██║╚════██║
██║ ██║███████╗██║ ██║███████╗ ██████╔╝███████╗ ██████╔╝██║ ██║██║ ██║╚██████╔╝╚██████╔╝██║ ╚████║███████║
╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝╚══════╝ ╚═════╝ ╚══════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═══╝╚══════╝
Builds Elasticsearch mapping for given module.
@elvanja
elvanja / grack_auth.rb
Created December 3, 2012 13:36
Gitlab grack authentication with ldap when username is not in schema
require "net/ldap"
=begin
fix for older versions, without username in User model
flow in general:
* authenticate user with ldap
return user's email if authenticated, otherwise nil
* if email retrieved
(ldap authenticated the user)
- find user in Gitlab database by that email
@elvanja
elvanja / grack_auth.rb
Created December 3, 2012 13:30
Gitlab grack authentication with ldap and possibly other providers
require "net/ldap"
# assumes ldap login is present in User.username
# flow in general:
# * find user either by email or username (using provided login)
# * if ldap enabled and user provider is ldap, authenticate over ldap
# * else validate plain password
module Grack
class Auth < Rack::Auth::Basic
attr_accessor :user, :project
@elvanja
elvanja / angular_rails_testing.md
Last active April 18, 2018 09:19
Angular JS and Rails testing
@elvanja
elvanja / deploy_discourse_to_heroku
Last active March 20, 2017 08:01
Helps deploy Discourse to Heroku with: * local asset precompiling * RedisCloud add-on * Autoscaler with Sidekiq add-on Details @ http://shcatula.wordpress.com/2013/07/08/deploying-discourse-to-heroku
#!/bin/sh
# http://stackoverflow.com/questions/3878624/how-do-i-programmatically-determine-if-there-are-uncommited-changes
require_clean_work_tree () {
# Update the index
git update-index -q --ignore-submodules --refresh
err=0
# Disallow unstaged changes in the working tree
if ! git diff-files --quiet --ignore-submodules --; then

Keybase proof

I hereby claim:

  • I am elvanja on github.
  • I am elvanja (https://keybase.io/elvanja) on keybase.
  • I have a public key whose fingerprint is 59E2 B0F6 C04F 68AF 1220 84B4 3C92 4F81 C91B B39A

To claim this, I am signing this object:

@elvanja
elvanja / Dockerfile
Last active January 8, 2016 10:11
Docker images to help recreate https://github.com/npm/npm/pull/10582 situation
# =====================================
# CentOS version
# =====================================
FROM centos
RUN yum install -y \
gcc-c++ \
make \
vim