Skip to content

Instantly share code, notes, and snippets.

@codephillip
codephillip / Q1_number_palindrome
Last active July 15, 2021 13:32
number_palindrome
QUESTION 1
TIME: 10 minutes
Number is a palindrome if it is equal to the number with digits in reversed order. For example, 5, 44, 171, 4884 are palindromes and 43, 194, 4773 are not palindromes.
Write a method palindrome_chain_length which takes a positive number and returns the number of special steps needed to obtain a palindrome. The special step is: "reverse the digits, and add to the original number". If the resulting number is not a palindrome, repeat the procedure with the sum until the resulting number is a palindrome.
If the input number is already a palindrome, the number of steps is 0.
Input will always be a positive integer.
For example, start with 87:
QUESTION 2
TIME: 5 minutes
What is the output of this line of code?
console.log((function x(n){return ((n > 1) ? n * x(n-2) : n)})(10));
package com.codephillip.hello;
public class Main {
public static void main(String[] args) {
divider();
}
}
QUESTION 5
CREDIT: http://www.cs.unc.edu/~stotts/COMP204/refactor/chap1.html
TIME: 15 minutes
Refactor the following code
public class DomainObject {
public DomainObject (String name) {
_name = name;
QUESTION 4
TIME: 5 minutes
What will be the output of this code?
var x = 21;
var girl = function () {
console.log(x);
var x = 20;
QUESTION 3
TIME: 5 minutes
Consider the following code. What will the output be, and why?
(function () {
try {
throw new Error();
} catch (x) {
var x = 1, y = 2;
def download_invoice(self, request, pk=None):
"""
Download Invoice Endpoint
---
omit_serializer: True
omit_parameters:
- query
"""
current_url = '{}?{}'.format(
reverse(request.resolver_match.url_name, kwargs={'pk': pk}),
@codephillip
codephillip / ParseXML.java
Created January 28, 2020 08:23
Extracts data from xml file on android local storage and extracts the data
private void parseXML(String targetFilePath) {
try {
FileInputStream is = new FileInputStream(targetFilePath);
XmlToJson xmlToJson = new XmlToJson.Builder(is, null).build();
JSONObject jsonObject = xmlToJson.toJson();
Timber.d("Content " + jsonObject.toString());
// get the root key.
// This prevents us from manually checking key. This is a special case
Iterator keys = jsonObject.keys();
@codephillip
codephillip / JavaFileContentExtractor.java
Created January 28, 2020 08:19
Gets access to Android(java) internal storage using the provided url
private String getFileContent(String targetFilePath) {
try {
FileInputStream fis = new FileInputStream(targetFilePath);
DataInputStream in = new DataInputStream(fis);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
StringBuilder sb = new StringBuilder();
while ((strLine = br.readLine()) != null)
sb.append(strLine);
Timber.d("form data");
@codephillip
codephillip / MainMenuActivity.java
Last active September 4, 2019 09:54
Moving the form download logic from FormDownloadList to MainMenuActivity. Based on ODK(https://github.com/opendatakit/collect)
/*
* Copyright (C) 2009 University of Washington
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express