Skip to content

Instantly share code, notes, and snippets.

View chauvd's full-sized avatar

Daniel Chauvin chauvd

View GitHub Profile
@chauvd
chauvd / carousel.html
Last active December 27, 2015 03:29
Carousel with RoR resource taken from scope query returning top 10 in db.
@chauvd
chauvd / application_controller.rb
Created October 22, 2013 16:15
Retrieve referer path given any method to be stored and or compared to session[:return_to] variable
def referer_path
request.get? ? request.url : request.referer
end
@chauvd
chauvd / qa5.java
Created October 13, 2013 13:53
Write a java program that finds two numbers in an array whose difference equals a number provided. Assume the number array is sorted from lowest to highest.
import java.util.LinkedHashMap;
import java.util.Random;
public class Main {
public static void main(String[] args) {
int[] arr1 = {0, 3, 4, 4, 5, 8, 9, 10, 45, 80};
int[] arr2 = {1};
int[] arr3 = {1,20};
int[] arr4 = {};
@chauvd
chauvd / substr.java
Created October 10, 2013 15:25
Substr Java without API
public class Main {
public static void main(String[] args) {
String splice = "This is a long string to substring from.";
System.out.println(substr(splice, 0, 4));
System.out.println(substr(splice, 5, splice.length()-1));
try {
System.out.println(substr(splice, -1, 6));
} catch (IndexOutOfBoundsException error) {
@chauvd
chauvd / qa4.java
Created October 8, 2013 20:12
Write a java program that determines if a given string is a palindrome.
public class Main {
public static void main(String[] args) {
String oddPal = "dadad";
String evenPal = "Daad";
String notPal = "not";
System.out.println(isPalindrome(oddPal));
System.out.println(isPalindrome(evenPal));
System.out.println(isPalindrome(notPal));
}
@chauvd
chauvd / qa3.java
Created October 8, 2013 18:49
Write a java program thats takes a string and a character as input and return the string without that character. Do not use repalce function. For eg google, g should return oole
public class Main {
public static void main(String[] args) {
String str = "google";
char remove = 'g';
StringBuilder builder = removeChar(str, remove);
System.out.println(builder);
}
@chauvd
chauvd / qa2.java
Created October 3, 2013 16:50
Write a function in Java which takes an Array of strings and from the array of strings returns only those strings which have a consecutive repetition of a particular letter for eg: if I/P is {"Dauresselam", "slab", "fuss", "boolean", "clap"} then O/P should be {"Dauresselam", "fuss", "boolean"} Also check for edge cases...consecutive char at the…
import java.util.ArrayList;
import java.util.List;
public class Main {
public static void main(String[] args) {
String[] words = {"Dauresselam", "slab", "fuss", "boolean", "clap", "ddan", "endd"};
List<String> results = new ArrayList<String>();
for (String word:words) {
if (word.length() <= 1) break;
@chauvd
chauvd / qa1.java
Last active December 24, 2015 14:19
Given a string say "ABCD". Now create a new string with duplicates of each character in the original string and append the reverse of the same string (with duplicates) excluding the last character.
public class Main {
public static void main(String[] args) {
String str = "ABCD";
StringBuilder builder;
for (int i = 0; i <= str.length()-1; i++) {
builder = expand(str.substring(0, str.length()-i));
System.out.println("final == " + builder.toString()+ builder.reverse().toString());
}
}
@chauvd
chauvd / html.sublime-build
Created November 19, 2012 04:31
Quick Sublime Text Build System for HTML files.
{
"working_dir": "${project_path:${folder:${file_path}}}",
"shell": true,
"osx":
{
"cmd": ["open $file"]
},
"windows":
{
"cmd": ["start $file"]