Skip to content

Instantly share code, notes, and snippets.

@jvmvik
jvmvik / .htaccess
Created July 6, 2014 15:37
HTACCESS Dokuwiki nice URL formatting: website.com/$section/$page
## Enable this to restrict editing to logged in users only
## You should disable Indexes and MultiViews either here or in the
## global config. Symlinks maybe needed for URL rewriting.
Options -Indexes -MultiViews +FollowSymLinks
## make sure nobody gets the htaccess files
<Files ~ "^[\._]ht">
Order allow,deny
Deny from all
@jvmvik
jvmvik / Install-node-npm.sh
Created July 23, 2014 19:30
Installing NODE + NPM on Linux / Mac
# Source: https://gist.github.com/isaacs/579814
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://www.npmjs.org/install.sh | sh
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# don't put duplicate lines in the history. See bash(1) for more options
# don't overwrite GNU Midnight Commander's setting of `ignorespace'.
HISTCONTROL=$HISTCONTROL${HISTCONTROL+:}ignoredups
@jvmvik
jvmvik / bsub.sh
Last active December 15, 2017 22:20
Running jobs in parallel, then merge in bash with the command "wait"
#!/bin/sh
#
# Submit a single test on LSF
# Wrapper around bsub command, then process log result.
#
# This script is used by run-tests-async.sh
#
# Usage:
#
# ./bsub.sh $command
@jvmvik
jvmvik / Singleton.js
Last active August 29, 2015 14:13
Singleton pattern implemented in NodeJS. Example: Shared database like neDB or MongoDB, Application configuration, Filter...
/***
* NodeJS module that implements the single pattern.
* http://en.wikipedia.org/wiki/Singleton_pattern
*
* The goals is to create the object: instance only one time
* thus the instance is shared in the source code.
*
* You must be aware that there is a risk to break
* the isolation principles.
*/
@jvmvik
jvmvik / group_example.rb
Created July 27, 2015 13:08
Example of Grouping with Ruby 2+ by using: group_by, Array, collection, subgroup
# Example of Grouping with Ruby
# features: group_by, Array, collection, subgroup
# Here the collection
# where #{group_name}_#{subgroup0}_#{subgroup1}...
collection = ['AA_A_B_C', 'BB_A_B_C', 'CC_A_B_C', 'AA_A_A_A', 'BB_B_B_B']
# To range allow to convert
# a subgroup to a range
#
# Remove a line from a file. Ruby 1.9 >
ruby -i.bak -ne 'print if not /POR_CHIE_DAT_RSVDC_WIDTH_PARAM|HNF_SLC_DSLICE_PARAM/' spec/porter_1_*.yml
@jvmvik
jvmvik / yml2yml.rb
Created February 25, 2016 18:09
Ruby Render YAML JSON like format.
#!/bin/usr/env ruby
#
# Ruby script to render a YAML file with a nice format.
# Read a YAML file format and render like JSON.
#
# File: input.yml
# {
# key1: "value",
# key2: {
# key3: "value3"
@jvmvik
jvmvik / webrick_virtualhost_example.rb
Last active February 29, 2016 13:47
Ruby Webrick: Example of Virtual Host.
# Ruby Webrick example of Virtual Host
#
# Your directory must contain a public/index.html file.
#
require 'webrick'
require 'json'
# Daemonize (production)
#WEBrick::Daemon.start
@jvmvik
jvmvik / mongodb_map_reduce.rb
Last active November 21, 2016 13:06
Ruby mongoDB map reduce
# Ruby mongoDB map reduce
# The mongoDB documentation missed totally to
# describes a simple usage for map reduce in Ruby.
# and the web is full of misleading example based on the previous API.
#
# This gist try to fill out the gap.
# First please read https://docs.mongodb.org/manual/tutorial/map-reduce-examples/
# below it is a simple Ruby implementation.
#
# @doc https://docs.mongodb.org/manual/core/map-reduce/