Skip to content

Instantly share code, notes, and snippets.

View paratechnical's full-sized avatar

Andrei Paraschiv paratechnical

View GitHub Profile
@paratechnical
paratechnical / gist:9655b4ef4108501b5a950afbd749aa36
Created April 15, 2018 11:33
Modify mp4 - moov atom at the front of the file (Fast Start)
//add compile 'net.ypresto.qtfaststartjava:qtfaststart:0.1.0' to build.gradle
String videoFileNameWithoutExtension = com.google.common.io.Files.getNameWithoutExtension(path2OutputFile);
File outputFile = new File(path2OutputFile); // Your outputFile file
String pathToParent = outputFile.getParent();
Path noStreamOutputFile = Paths.get(pathToParent, videoFileNameWithoutExtension + "_nostream.mp4");
Files.move(outputFile.toPath(), noStreamOutputFile);
try {
QtFastStart.fastStart(new File(noStreamOutputFile.toString()), outputFile);
@paratechnical
paratechnical / Prefix Tree Autocomplete Gist 3
Created February 1, 2015 22:06
Gist 3 from the article autocomplete functionality using prefix trees
Tree prefixTree = new Tree();
prefixTree.AddWord("abc");
prefixTree.AddWord("abcd");
prefixTree.AddWord("abcde");
prefixTree.AddWord("abcdef");
prefixTree.AddWord("ab123cd");
prefixTree.AddWord("abc123d");
prefixTree.AddWord("abc132d");
@paratechnical
paratechnical / autocomplete prefix trees gist 2
Created February 1, 2015 22:01
Gist 2 from the article Autocomplete functionality using prefix trees
/// <summary>
/// get the autocomplete matches given the input
/// </summary>
/// <param name="query">the input</param>
/// <returns>the list of autocomplete matches</returns>
public List<string> GetMatches(string query)
{
StringBuilder sbPrevious = new StringBuilder();
char[] chars = query.ToCharArray();
Node currentNode = _root;
@paratechnical
paratechnical / Prefix tree autocomplete functionality part 1
Created February 1, 2015 21:52
Gist 1 from article Autocomplete functionality using prefix trees
private List<string> subsequentStrings;
/// <summary>
/// Create a prefix tree - the root node should always store ' '
/// Initializae the list that will store the strings
/// found during the autocomplete process
/// </summary>
public Tree()
{
_root = new Node(' ');
open System.Collections.Generic;
//the trie node type which is stores a char, a bool to mark the end of the node and a list of all it's subnodes
type TrieNode = TrieNode of (char * bool * TrieNode list) with
//just a getter the char stored
member this.Char = match this with TrieNode(c,weh,subnodes) -> c
//get the first node that is a subnode of the current node and stores the char passed as parameter (c)
//this returns a list which can be either empty or have one element this is probably not the best option since there will never be
//more than one element in the list but I am new to F#
member this.GetChild(c:char) = match this with TrieNode(c,weh,subnodes) -> match List.tryFind (fun (this:TrieNode) -> this.Char = c) subnodes with
var tree = new Tree();
tree.Insert("romane");
tree.Insert("romanus");
tree.Insert("romulus");
tree.Insert("rubens");
tree.Insert("ruber");
tree.Insert("rubicon");
tree.Insert("rubicundus");
Console.WriteLine("predecessor of the word \"romanes\":" + tree.FindPredecessor("romanes"));
public class Tree
{
/// <summary>
/// store the tree's root
/// </summary>
private Node _root;
/// <summary>
/// construct a new tree with it's root
/// </summary>
@paratechnical
paratechnical / C# radix tree node
Created June 4, 2012 15:50
C# radix tree node
/// <summary>
/// represents a node in the radix tree
/// stores:
/// a label - string that the tree holds
/// a list of the node's subnodes - a list of other objects of this type
/// </summary>
public class Node
{
public Node()
{
@paratechnical
paratechnical / MergeDocs
Created June 4, 2012 15:42
Merging 2 word 2007(open xml) documents
static void MergeDocs(string doc1Path,string doc2Path)
{
using (var doc2FileStream = File.Open(doc2Path, FileMode.Open))
{
using (WordprocessingDocument doc2 = WordprocessingDocument.Open(doc2FileStream, true))
{
var doc2Body = (Body)doc2.MainDocumentPart.Document.Body.CloneNode(true);
using (var doc1FileStream = File.Open(doc1Path, FileMode.Open))
{