Skip to content

Instantly share code, notes, and snippets.

# Remove file from GIT index
git rm --cached my_file
git rm --cached -r my_directory
@radium226
radium226 / play.sh
Created April 29, 2014 08:51
Pick random mp3 files and generate a XSPF playlist to play with VLC
find "." -name "${1:-"*.jar"}" -type "f" -print0 | \
shuf -z | \
awk -v limit="${2:-"50"}" 'BEGIN { RS = "\0" } ; NR <= limit { printf("%s%s", $0, "\0") }' | \
xargs -I {} -0 realpath -z "{}" | \
awk '
BEGIN { RS = "\0" ; printf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<playlist version=\"1\" xmlns=\"http://xspf.org/ns/0/\">\n\t<trackList>\n") } ; { printf("\t\t<track>%s</track>\n", $0) } ; END { printf("\t</trackList>\n</playlist>\n") }' | \
vlc -
@radium226
radium226 / MapListUsingRx.java
Last active August 29, 2015 14:11
Map a heavy function over a List using a pool of threads with the help of Rx.
import java.util.List;
import java.util.Arrays;
import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import rx.Observable;
import rx.schedulers.Schedulers;
@radium226
radium226 / timeline_aggregation.sql
Last active August 29, 2015 14:11
Here is an example on how to do a an aggregation over a timeline.
CREATE TABLE
t_intervals (
begin_time DATE,
end_time DATE,
category VARCHAR2(5),
code VARCHAR2(5),
value NUMBER
);
INSERT INTO t_intervals(begin_time, end_time, category, code, value) VALUES (to_date('08:00', 'HH24:MI'), to_date('08:30', 'HH24:MI'), 'A', '#1', 7);
@radium226
radium226 / dbms_sql-variable_binding.sql
Last active August 29, 2015 14:11
This is an example on how to use named parameters.
CREATE TABLE
t_texts (
text VARCHAR2(10)
);
DECLARE
v_cursor NUMBER;
v_sql VARCHAR2(32767) := 'INSERT INTO $$TABLE$$(text) VALUES (:text)';
v_table VARCHAR2(30) := 'T_TEXTS';
v_value VARCHAR2(10) := 'Hello! ';
@radium226
radium226 / rollup_sum.sql
Last active August 29, 2015 14:11
This is an example on how to compute a rollup sum over a hierarchy.
CREATE TABLE
t_folders (
id INTEGER,
parent_id INTEGER,
name VARCHAR2(100)
);
CREATE TABLE
t_files (
id INTEGER,
@radium226
radium226 / timeline_overlapping.sql
Created January 13, 2015 11:07
This is an example on how to compute overlaps on a timeline.
-- 1. T_INTERVALS:
-- [-----------------------------[ #1
-- 08:00 08:30
-- [---------[ #2
-- 08:10 08:20
-- [-------------------[ #3
-- 08:40 09:00
-- [----------[ #4
-- 08:35 08:45
-- [---------[ #5
@radium226
radium226 / interval_matching.sql
Created January 13, 2015 14:16
Example on match intervals presence at the same time.
-- T_INTERVALS:
-- [-----------------------------[ #1 O
-- 08:00 08:30
-- [---------[ #2 X
-- 08:10 08:20
-- [-------------------[ #3 O
-- 08:40 09:00
-- [----------[ #4 X
-- 08:35 08:45
-- [---------[ #5 O
#!/bin/sh
# Ignore some files by extension
ack --ignore-file="ext:${extension_1},${extension_2}" "${rexgep}"
@radium226
radium226 / round_to_multiple.sql
Created January 15, 2015 14:21
Example on how to round numbers and dates to the closest multiple.
DECLARE
FUNCTION
round_to_multiple(
in_number IN NUMBER,
in_multiple IN NUMBER
)
RETURN
NUMBER
IS