Leonard  Paucek

Leonard Paucek

1667326740

Shorturl Bundle: Provides Short Urls for Your Symfony2 Project

Provides short urls for your Symfony2 Project.

Note: This bundle is under development. Things will change and might break. Feedback is very welcome!

About

This Bundle allows you to

  • Generate short urls
  • Manage redirections from short to long urls

The bundle is based on the shorturl class by Jonathan Snook.

Installation

Using Composer, add to composer.json:

{
    "require": {
        "fabstei/shorturl-bundle": "0.2.0"
    }
}

Then install/update your vendors:

php composer.phar update

Add the bundle to your AppKernel.php:

new Fabstei\ShorturlBundle\FabsteiShorturlBundle(),

Update your doctrine database schema (doctrine:schema:update --force)

Import the routes from your routing.yml:

# Redirection from short to long urls
redirect:
    resource: "@FabsteiShorturlBundle/Resources/config/routing/redirect.yml"
    #hostname_pattern: example.com
    #prefix: /shorturls

# Shorturl management
shorturl:
    resource: "@FabsteiShorturlBundle/Resources/config/routing/url.yml"

The optional hostname pattern (new in Symfony 2.2) allows you to use a seperate domain for your short urls.

Configuration

The bundle provides sensible default values but one might want to customize the codeset used to generate unique tokens (used as short urls).

fabstei_shorturl:
    codeset: abcABC123-_! # Default: abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ23456789

Usage

The bundle comes with two services:

It also provides a controller to handle redirections as well as a controller, views and forms to manage the redirections (by default accessible from /url-manager). Custom shorturls can be used to replace the default tokens (calculated from the redirection id). Furthermore, you may use _locale anywhere in the long urls you store, which is replaced by the current requests locale on redirection.

Both services are also accessible via cli commands:

php app/console fabstei:shorturl:add    # Add a long url, returns the short token
php app/console fabstei:shorturl:get    # Retrieve a long url associated with a token
php app/console fabstei:shorturl:update # Update the long url associated with a token
php app/console fabstei:shorturl:remove # Remove a redirection
php app/console fabstei:shorturl:list   # Get a list of all stored redirections

php app/console fabstei:token:codeset   # Get the codeset used to generate tokens
php app/console fabstei:token:encode    # Calculate a token from an integer
php app/console fabstei:token:decode    # Calculate the integer from a given token

TODO

  • Add proper tests
  • Improve general code quality

Dependencies

Credits


Download Details:

Author: fabstei
Source Code: https://github.com/fabstei/shorturl-bundle

#symfony 

Shorturl Bundle: Provides Short Urls for Your Symfony2 Project
Gordon  Taylor

Gordon Taylor

1657251660

Sublevel-prefixer: Prefix A Key with A Sublevel Prefix

sublevel-prefixer

Prefix a key with a sublevel prefix

npm install sublevel-prefixer

Usage

var prefixer = require('sublevel-prefixer')
var prefix = prefixer('!') // use '!' as the separator

// using string keys
console.log(prefix('my-prefix', 'my-key')) // !my-prefix!my-key

// using binary keys
console.log(prefix('my-prefix', new Buffer('my-key'))) // returns above as a buffer

Author: Mafintosh
Source Code: https://github.com/mafintosh/sublevel-prefixer 
License: MIT license

#javascript #prefix #key 

Sublevel-prefixer: Prefix A Key with A Sublevel Prefix
Veronica  Roob

Veronica Roob

1651860000

Migrations: PHP 5.3 Migration Manager

#What are Database Migrations?

Migrations are a convenient way for you to alter your database in a structured and organized manner. You could edit fragments of SQL by hand but you would then be responsible for telling other developers that they need to go and run them. You’d also have to keep track of which changes need to be run against the production machines next time you deploy.

Above from Rails guide.

This Migrations library was inspired by earlier works such as mysql-php-migrations, and implementations found in both Codeigniter and Fulephp frameworks.

##Whats different?

  1. Written with php 5.3 and uses Symfony2 components and Doctrine DBAL
  2. Allows each project to define templates using Twig.
  3. Uses Doctrine DBAL Schema manager to write platform independent migrations or use normal SQL DDL to control your database.
  4. All commands accept a DSN allowing scripting to apply your migrations to many databases.

##Getting Started

###Installing

This library can be accessed through Composer

Using dev mode as most likely don't want this component in a release cycle.

Create composer.json add add the following.

{    "require" : {    },    "require-dev" : {        "icomefromthenet/migration" : "dev-master"    } }

##Running the commands

Create the project folder and then run the int function using the vendor bin migrate.php. Note all commands are prefixed with app:

mkdir migrations
cd migrations
../vendor/bin/migrate.php app:init 

Create the Config for your database answer the questions and a config will be created.

../vendor/bin/migrate.php app:config 

Run install to add migrations tacking database table to the schema:

../vendor/bin/migrate.php app:install 

Add your first migration by using the add command (optional description slug):

../vendor/bin/migrate.php app:add #prefix# 

Run up command to install the change

../vendor/bin/migrate.php app:up 1

Run status to find the head migration

../vendor/bin/migrate.php app:status

 

Run status to find the head migration

../vendor/bin/migrate.php app:status

Requirements

  • php 5.3
  • CLI.
  • SPL
  • PDO
  • Composer

Author: icomefromthenet
Source Code: https://github.com/icomefromthenet/Migrations
License: MIT License

#php #migrate 

Migrations: PHP 5.3 Migration Manager

Shorturl-bundle: ShorturlBundle for Symfony2

Provides short urls for your Symfony2 Project.

Note: This bundle is under development. Things will change and might break. Feedback is very welcome!

About

This Bundle allows you to

  • Generate short urls
  • Manage redirections from short to long urls

The bundle is based on the shorturl class by Jonathan Snook.

Installation

Using Composer, add to composer.json:

{
    "require": {
        "fabstei/shorturl-bundle": "0.2.0"
    }
}

Then install/update your vendors:

php composer.phar update

Add the bundle to your AppKernel.php:

new Fabstei\ShorturlBundle\FabsteiShorturlBundle(),

Update your doctrine database schema (doctrine:schema:update --force)

Import the routes from your routing.yml:

# Redirection from short to long urls
redirect:
    resource: "@FabsteiShorturlBundle/Resources/config/routing/redirect.yml"
    #hostname_pattern: example.com
    #prefix: /shorturls

# Shorturl management
shorturl:
    resource: "@FabsteiShorturlBundle/Resources/config/routing/url.yml"

The optional hostname pattern (new in Symfony 2.2) allows you to use a seperate domain for your short urls.

Configuration

The bundle provides sensible default values but one might want to customize the codeset used to generate unique tokens (used as short urls).

fabstei_shorturl:
    codeset: abcABC123-_! # Default: abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ23456789

Usage

The bundle comes with two services:

It also provides a controller to handle redirections as well as a controller, views and forms to manage the redirections (by default accessible from /url-manager). Custom shorturls can be used to replace the default tokens (calculated from the redirection id). Furthermore, you may use _locale anywhere in the long urls you store, which is replaced by the current requests locale on redirection.

Both services are also accessible via cli commands:

php app/console fabstei:shorturl:add    # Add a long url, returns the short token
php app/console fabstei:shorturl:get    # Retrieve a long url associated with a token
php app/console fabstei:shorturl:update # Update the long url associated with a token
php app/console fabstei:shorturl:remove # Remove a redirection
php app/console fabstei:shorturl:list   # Get a list of all stored redirections

php app/console fabstei:token:codeset   # Get the codeset used to generate tokens
php app/console fabstei:token:encode    # Calculate a token from an integer
php app/console fabstei:token:decode    # Calculate the integer from a given token

TODO

  • Add proper tests
  • Improve general code quality

Dependencies

Credits

Author: Fabstei
Source Code: https://github.com/fabstei/shorturl-bundle 
License: 

#php #symfony 

Shorturl-bundle: ShorturlBundle for Symfony2
Madisyn  Lakin

Madisyn Lakin

1646943900

How to Convert Prefix to Postfix Expression using STACK in C++

 In this tutorial, we will study write a C++ program to convert prefix to postfix expression using stack data structure. We will take the pesudocode from the previous tutorial and convert it into a C++ program.
 

#datastructures  #stack  #prefix  #postfix #cpluplus 

How to Convert Prefix to Postfix Expression using STACK in C++
Madisyn  Lakin

Madisyn Lakin

1646929320

How to Convert Postfix to Prefix Expression using STACK in C++

 In this tutorial, we will study write a C++ program to convert postfix to prefix expression using stack data structure. We will take the pesudocode from the previous tutorial and convert it into a C++ program.
You can use any other programming language too because the pseudocode will remain the same.

#cpluplus #datastructure #stack #prefix 

How to Convert Postfix to Prefix Expression using STACK in C++
Madisyn  Lakin

Madisyn Lakin

1646922014

How to Convert Postfix To Prefix Expression using STACK Data Structure

Learn how to convert postfix to prefix expression using stack data structure using a set of rules. In this tutorial we will study and understand the rules, pseudocode as well as the working of stack data structure in this postfix to prefix conversion. One of the application of stack data structure is to convert prefix to infix expression because of its properties and mode of operation that is Last In First Out (LIFO) or First In Last Out (FILO)

#datastructures #stack #prefix 

How to Convert Postfix To Prefix Expression using STACK Data Structure
Madisyn  Lakin

Madisyn Lakin

1646914740

How to Convert an Postfix Expression To A Prefix Expression & Reverse

In this tutorial we will learn to convert an postfix expression to a prefix expression and reverse process without using stack data structure in a manual way. We will solve 3 examples each for prefix to postfix and postfix to prefix using manual steps. 


#postfix #prefix #stackapplication #datastructures 

How to Convert an Postfix Expression To A Prefix Expression & Reverse
Mitchel  Carter

Mitchel Carter

1597777200

Minimize Cost to reduce the Array to a single element by given operations

Given an array a[] consisting of N integers and an integer K, the task is to find the minimum cost to reduce the given array to a single element by choosing any pair of consecutive array elements and replace them by (a[i] + a[i+1]) for a cost K * (a[i] + a[i+1]).

Examples:

Input: a[] = {1, 2, 3}, K = 2 
Output: 18 
Explanation: 
Replacing {1, 2} by 3 modifies the array to {3, 3}. Cost 2 * 3 = 6 
Replacing {3, 3} by 6 modifies the array to {6}. Cost 2 * 6 = 12 
Therefore, the total cost is 18
Input: a[] = {4, 5, 6, 7}, K = 3 
Output: 132

#arrays #dynamic programming #recursion #prefix-sum

Minimize Cost to reduce the Array to a single element by given operations
Brain  Crist

Brain Crist

1597474800

Smallest String consisting of a String S exactly K times as a Substring

Given a string S of length **N **and integer K, find the smallest length string which contains the string **S **as a sub string exactly K times.

Examples:

Input:_ S = “abba”, K = 3_

_Output: _abbabbabba

Explanation:_ The string “abba” occurs K times in the string abbabbabba, i.e. {abbabbabba, abbabbabba, abbabbabba}_

Input:_ S = “geeksforgeeks”, K = 3_

Output:_ “geeksforgeeksforgeeksforgeeks”_

Approach: To optimize the above approach, find the Longest Proper Prefix which is also a suffix for the given string S, and then generate a substring of S excluding the longest common prefix and add this substring to the answer exactly K – 1 times to the original string. Follow the below steps to solve the problem:

  • Find the length of the longest proper prefix using KMP algorithm.
  • Append substring **S.substring(N-lps[N-1]) **to S, exactly K-1 times.
  • Print the answer.
  • Below is the implementation of the above approach.

C++

  • // C++ Program to implement

  • // the above approach

  • #include <bits/stdc++.h>

  • **using** **namespace** std;

  • // KMP algorithm

  • **int**``* kmp(string& s)

  • {

  • **int** n = s.size();

  • **int**``* lps = **new** **int**``[n];

  • lps[0] = 0;

  • **int** i = 1, len = 0;

  • **while** (i < n) {

  • **if** (s[i] == s[len]) {

  • len++;

  • lps[i] = len;

  • i++;

  • }

  • **else** {

  • **if** (len != 0) {

  • len = lps[len - 1];

  • }

  • **else** {

  • lps[i] = 0;

  • i++;

  • }

  • }

  • }

  • **return** lps;

  • }

  • // Function to return the required string

  • string findString(string& s, **int** k)

  • {

  • **int** n = s.length();

  • // Finding the longest proper prefix

  • // which is also suffix

  • **int**``* lps = kmp(s);

  • // ans string

  • string ans = ""``;

  • string suff

  • = s.substr(0, n - lps[n - 1]);

  • **for** (``**int** i = 0; i < k - 1; ++i) {

  • // Update ans appending the

  • // substring K - 1 times

  • ans += suff;

  • }

  • // Append the original string

  • ans += s;

  • // Returning min length string

  • // which contain exactly k

  • // substring of given string

  • **return** ans;

  • }

  • // Driver Code

  • **int** main()

  • {

  • **int** k = 3;

  • string s = "geeksforgeeks"``;

  • cout << findString(s, k) << endl;

  • }

  • Output:

geeksforgeeksforgeeksforgeeks
  • Time Complexity:_ O(N*K )_
  • Auxiliary Space:_ O(K* N)_
  • Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

#dynamic programming #mathematical #pattern searching #searching #strings #prefix #substring #suffix

Smallest String consisting of a String S exactly K times as a Substring

Sort an array of strings lexicographically based on prefix

Given an array of strings arr[] of size N, the task is to sort the array of strings in lexicographical order and if while sorting for any two string A and string B, if string A is prefix of string B then string B should come in the sorted order.

Examples:

Input:_ arr[] = {“sun”, “moon”, “mock”}_

Output:

mock

moon

sun

Explanation:

The lexicographical sorting is mock, moon, and sun.

Input:_ arr[] = {“geeks”, “geeksforgeeks”, “geeksforgeeks”}_

Output:

geeksforgeeks

geeksfor

geeks

Approach: The idea is to sort the given array of strings using the inbuilt sort function using the below comparator function. The comparator function used to check if any string occurs as a substring in another string using compare() function in C++ then, it should arrange them in decreasing order of their length.

**bool** my_compare(string a, string b)

{

// If any string is a substring then

// return the size with greater length

**if** (a.compare(0, b.size(), b) == 0

|| b.compare(0, a.size(), a) == 0)

**return** a.size() & gt;

b.size();

// Else return lexicographically

// smallest string

**else** **return** a & lt;

b;

}

Below is the implementation of the above approach:

  • C++

// C++ program for the above approach

#include <bits/stdc++.h>

**using** **namespace** std;

// Function to print the vector

**void** Print(vector<string> v)

{

**for** (``**auto** i : v)

cout << i << endl;

}

// Comparator function to sort the

// array of string wrt given conditions

**bool** my_compare(string a, string b)

{

// Check if a string is present as

// prefix in another string, then

// compare the size of the string

// and return the larger size

**if** (a.compare(0, b.size(), b) == 0

|| b.compare(0, a.size(), a) == 0)

**return** a.size() > b.size();

// Else return lexicographically

// smallest string

**else**

**return** a < b;

}

// Driver Code

**int** main()

{

// GIven vector of strings

vector<string> v = { "batman"``, "bat"``, "apple" };

// Calling Sort STL with my_compare

// function passed as third parameter

sort(v.begin(), v.end(), my_compare);

// Function call to print the vector

Print(v);

**return** 0;

}

Output:

apple
batman
bat

Time Complexity:_ O(N*log N)_

Auxiliary Space:_ O(1)_

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

#arrays #sorting #strings #lexicographic-ordering #prefix

Sort an array of strings lexicographically based on prefix
Brain  Crist

Brain Crist

1596627360

Minimum count of elements required to obtain the given Array

Given an array arr[] consisting of N integers, the task is to find the array K[] of minimum possible length such that after performing multiple mirror operations on K[], the given array arr[] can be obtained.

Mirror Operation:_ Appending all the array elements to the original array in reverse order._

Illustration:

arr[] = {1, 2, 3}

After 1st mirror operation, arr[] modifies to {1, 2, 3, 3, 2, 1}

After 2nd mirror operation, arr[] modifies to {1, 2, 3, 3, 2, 1, 1, 2, 3, 3, 2, 1}

Examples:

Input:_ N = 6, arr[] = { 1, 2, 3, 3, 2, 1 }_

Output:_ 3_

Explanation:

Subarrays {1, 2, 3} and {3, 2, 1} are mirror images of each other.

Single mirror operation on {1, 2, 3} obtains the given array.

Therefore, the minimum number of elements required is 3.

Input:_ N = 8, arr[] = { 1, 2, 2, 1, 1, 2, 2, 1 }_

Output:_ 2_

Explanation:

Subarrays {1, 2, 2, 1} and {1, 2, 2, 1} are mirror images of each other.

Subarray {1, 2} and {2, 1} are mirror images of each other.

{1, 2} -> {1, 2, 2, 1} -> {1, 2, 2, 1, 1, 2, 2, 1}

Therefore, the minimum number of elements required is 2.

Naive Approach:

The simplest approach to solve the problem is to generate all the possible subarrays from the given array of size less than equal to N/2 and, for each subarray, check if performing mirror operation gives the array arr[] or not. Print the minimum length subarray satisfying the condition. If no subarray is found to be satisfying, print No.

Time Complexity:_ O(N3)_

Auxiliary Space:_ O(N)_

Efficient Approach:

The above approach can be further optimized using Divide and Conquer technique. Follow the steps below to solve the problem:

  • Initialize a variable K = N and then, check whether the prefix of A[] of length K is a palindrome or not.
  • If the prefix of length **K **is a palindrome then divide K by 2 and perform the above checking.
  • If the prefix is not a palindrome then the answer is the current value of K.
  • Keep checking while K > 0 until K is odd.
  • If K is odd, then print the current value of K.

Below is the implementation of the above approach:

  • C++

// C++ Program to implement

// the above approach

#include <bits/stdc++.h>

**using** **namespace** std;

// Function to find minimum number

// of elements required to form A[]

// by performing mirroring operation

**int** minimumrequired(``**int** A[], **int** N)

{

// Initialize K

**int** K = N;

**int** ans;

**while** (K > 0) {

// Odd length array

// cannot be formed by

// mirror operation

**if** (K % 2 == 1) {

ans = K;

**break**``;

}

**bool** ispalindrome = 1;

// Check if prefix of

// length K is palindrome

**for** (``**int** i = 0; i < K / 2; i++) {

// Check if not a palindrome

**if** (A[i] != A[K - 1 - i])

ispalindrome = 0;

}

// If found to be palindrome

**if** (ispalindrome) {

ans = K / 2;

K /= 2;

}

// Otherwise

**else** {

ans = K;

**break**``;

}

}

// Return the final answer

**return** ans;

}

// Driver Code

**int** main()

{

**int** a[] = { 1, 2, 2, 1, 1, 2, 2, 1 };

**int** N = **sizeof** a / **sizeof** a[0];

cout << minimumrequired(a, N);

**return** 0;

}

Output:

2

Time Complexity:_ O(N*log N)_

_Auxiliary Space: _O(N)

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

#arrays #divide and conquer #greedy #array-rearrange #palindrome #prefix

Minimum count of elements required to obtain the given Array