instruction stringlengths 71 71.9k |
|---|
In https://stackoverflow.com/a/39299060, I wrote the following program.
#include <fstream>
#include <iostream>
#include <string>
static std::string str_xor(const std::string &data, const std::string &key) {
std::string result(data.size(), '\0');
for (std::size_t i = 0, i < data.size(); i++) {
result[i] = data... |
Can someone please evaluate my code and let me know how I can improve it?
public class ArrayListImplementation {
static class ListNode<T> {
private T value;
public ListNode(T val) {
this.value = val;
}
public T getValue() {
return this.value;
}
public String toString() {
... |
A few days ago I wanted to build a tools to cut a long text into one hundred-letters strings with the number of the tweets and which part of the tweets the tweet belongs to.
I tried to have a tweet with one-hundred characters long but I could not find anything relevant to [1/x]
This is my tool:
import tweepy
n = 100... |
So I made a class for playing a sound in JavaFX when a button is pressed, a window pops up... I don't know about the quality of the code though. I don't know if I used the best way to play the sound. It's meant to be used to play small mp3 or wav files (not longer than 5 seconds) I made it so you can adjust the volume ... |
Given a vector of seller orders (asks) of a certain product (each order having a price) and buyer orders (bids) of the same product, I'm creating a function that resolves the auction by matching the best sellers (lowest asked price) with the best buyers (higher offered price) and then clears the market by selecting a p... |
I'm learning Scala, and I wrote a program to estimate the value of Pi. When I'm using multiple threads, it takes 5-6 times longer to calculate the same iterations. I wrote a similar program in Java, with plain old threads, and with ExecutorService , and the results are the same.
Why is this the case?
(I have 4 cores in... |
I'm very new to C and have extensive experience with C# and very little with C++, but basically none with C.
I wrote a small program that declares a singly-linked list struct, a few methods operating on the list, and then uses it from the main method. Even though I've read about it a lot, this is only my second/third p... |
The LinkedList nodes can be 1-->2-->3-->4, where --> indicates next. For their random pointers: 1--> 2, 2--> 4 3-->2 4--1. There can be duplicate data values of the nodes. I'm looking to see if the solution can be improved upon.
class Node
{
int data;//Node data
Node next, random;//Next and random reference
//Node con... |
Is there a faster way of getting the key of 1 or 2 by using the accs value for my getID function? Unfortunately I cannot use an inverse dict due to the fact I'm using a list for the value which causes a unhasable list error. Mainly I'm worried more when the db gets larger in size the getID function will take longer to ... |
A simple reworking of the Bash date command to my own personal liking. Possibly a rather trivial task; I just wanted the date and time to be in the form of:
Fri Sep 2 2016
11:37 P.M.
I think this accomplishes that:
#!/bin/bash
today() {
now="$(date | awk '{ OFS=" "; print $1,$2,$3,$6 }')"
h="$(date "+%H")"
... |
I've made a JavaScript library that retrieves a Google Spreadsheet. It's something like Sheetrock.js, while mine is just a less powerful prototype.
I've uploaded the source code and example in GitHub. But you can just see the implementation and demo in JSFiddle. A sample spreadsheet is here.
Since I am not not a JavaSc... |
Given that I have a set of vectors(or called vector-group), like \$\{\mathbf U_1,\mathbf U_2,\cdots,\mathbf U_n\}\$. Below is a simple instance U1, U2, U3
U1 = {0.25, 0.25, 0.5, 0.5, 0.75, 0.75, 0.8};
U2 = {0.21, 0.25, 0.3, 0.6, 0.7, 0.8};
U3 = {0.25, 0.3, 0.7, 0.8};
Now I would like to calculate their common vector ,... |
Here is the classic K-means clustering algorithm implemented in Python 3. My main concern is time/memory efficiency and if there are version specific idioms that I could use to address issues of the former.
import numpy as np
class kmeans():
'''
Implementation of classical k-means clustering algorithm
para... |
I am taking a beginning programming class and have been given the assignment to create a calendar as described in the title. Per the assignment the user entering offset of 0 will begin the calendar on a monday and 6 will start on sunday. There are to be 4 spaces per column and the request for input should prompt the ... |
This header implements a very simple set of C (only) functions for logging.
This is part of a larger collection of utility functions aimed to be used during the development process, meaning that they are intended to provide quick, easy to use solutions that could be replaced in the production code if needed.
To ease wi... |
I have coded a free .psd layout for the first time. I did not make it responive because I would like to know if the code is correct.
The layout's appearance in Firefox and Chrome seems to be ok (though in Firefox there's a bit of white space), but I know sometimes your code can be incorrect even if it looks good. I don... |
I was posed with a challenge when trying to load XML files from Stack Exchange into a SQL Server database; some of these XML files are extremely large (largest one being a whopping 67 GB in a single XML file), so much so that the database just cannot handle them without throwing a System.OutOfMemoryException.
After som... |
The "Rope Intranet" problem from Google Codejam 2010 asks us to count the number of intersections (black circles) in a planar straight-line graph like this:
That is, with each line segment having one endpoint with \$x=x_0\$ and the other with \$x=x_1\$.
Input
The first line of the input gives the number of test cas... |
I am trying to build a multiple file uploader with jQuery and Ajax. I would like to know how this code could be improved. I feel the client side validation of file types in my code are presently not good enough.
app.js
$(document).ready(function() {
$('#upload').click(function () {
$('input[type=file]').cli... |
I'm developing, just for fun and learning, a TypeScript Class that creates an Array<Array<string>> that represents a pyramid. So, for length = 5 the array would look like :
[
['X', 'X', '0', 'X', 'X'],
['X', '0', '0', '0', 'X'],
['0', '0', '0', '0', '0']
]
The class constructor can take a few arguments:
The fin... |
This question is continuation of: Sending email using libcurl
I developed a class to send email. Does this code have any problems? Is it thread-safe?
#include <ctime>
#include <cstring>
#include <curl/curl.h>
class Email
{
public:
Email (const std::string &to,
const std::string &from,
... |
I am given pasted data from a table, so I have spaces as delimiters and in some of the fields I don't care about. I want the first field and the last three fields, and got them using this code:
testdata = """8/5/15 stuffidontneed custid locid 55.00
8/9/15 stuff i really dont need with extra spaces custid otherlocid 79.... |
I'm writing a basic wrapper around a restful service that returns a list of Stores. I'm using RestSharp which I'm injecting into the class.
Naturally, I want to make it completely testable (that's a major requirement!).
I'm also thinking that it could be more generic i.e. GetStores but I'm struggling how to do as I nee... |
Task aim: Given a list of integers and a single sum value, return the first two values (parse from the left please) in order of
appearance that add up to form the sum.
I've been trying to make my implemented function below run faster (less than 7000ms) and taking into account records upwards of 10,000,000 items.
Wh... |
I don't have a lot of experience in C++; I'm more of a C# guy. I'm trying to convert some Matlab image processing code to C++. I would appreciate any feedback about C++ coding conventions, which data structures to use, what kills performance, and anything which is considered to be good or bad coding style for C++. I'm ... |
I have a select box with some options in it and a input box. I have to filter the values of select box on the basis of the keyword entered in the text box.
JavaScript
function filter() {
var keyword = document.getElementById("search").value;
var select = document.getElementById("select");
for (var i = 0; i ... |
Please review my implementation. I know there is already an implementation in Java, but I just wanted to come up with my implementation. Let me know if I can improve this.
import java.util.NoSuchElementException;
public class LinkedListImplementation<T> {
private int size;
private ListNode<T> head;
static... |
The requirement is to iterate over a list of Foos, and when 2 Foos have the same id merge their list of inputs together and obtain a new object.
I have achieved this with 2 streams and a private method to do this:
import java.util.HashSet;
import java.util.Set;
class Foo {
private String id;
private Set<String... |
update:
So, this is weird, I just reinstalled Adobe Animate, and now, when I do ctrl+enter (test movie), it pulls up an AIR window, and plays my app, and it works smooth as butter! (now I'm just not able to install a published package because I screwed up something with my certificate...)
I have just posted 1 out of 4 ... |
Please review my Stack implementation and let me know if you have any suggestions.
public class StackImplementation<T> {
private StackNode<T> top;
private StackNode<T> head;
private int size;
static class StackNode<T> {
private T value;
private StackNode<T> next;
public StackNode(T val) {
this.val... |
I am attempting to validate a set of business rules in order for a user to successfully add to cart. The rules vary from requiting to add/decline a requested add-on to not having more then 60 items in your shopping cart.
For my end goal, I need to be able to have several dozen rule sets and if any return false then exe... |
For a Laravel project I needed to show latest three blog posts on the homepage.
The blog was made with Wordpress and after some research I found a cool plugin called REST API that allows to get a json object of posts.
I made a Laravel Controller that uses curl to get the posts and send the response to jquery in the hom... |
I am a college student and started my first week of C++ and we were given an assignment to convert a Java program that calculate the interest on a series of loans given the amount of the principal, the annual interest rate, and the number of days in a sentinel loop into C++.
Here is what we were given:
import java.uti... |
This finds the prime factors of a number given in a variable. Is it efficient or in need of improvement?
public class PrimeFactorFinder {
public static void main(String args[]){
long n = 18;
long md = 2;
while(n!=java.lang.Math.sqrt(n)){
if(n%md==0){
System.out.p... |
From a React course I'm taking:
I could implement most of the demands.
A life-demo can be seen here:
http://n-or.de/news/#/
You have to click the "News" and "Photos" links on the right side for getting to the subpages.
Here's the code of the relevant components:
main.jsx
var React = require('react');
var ReactDO... |
This is a very simple text-based "game" I made in Java. The whole idea is to repeatedly type "eat/sip _____" until you eat all the food and win.
(Pertaining to skill level) I have been programming in Java for a little over two years, in high school. I feel I can be considered a beginner, but not quite enough to warrant... |
I have been using Scala as a means to learn Functional Programming and writing better code. However, I have some questions regarding some exercises or if there's a better way to approach them.
In the exercises below, I have already defined the functions foldLeft, foldRight,append, sum, product, head and tail.
HARD - ... |
I'm currently reviewing some different ways to have reusable components enforcing both most of the style & logic. The use case is a generic MainList with children components (eg. MainListToolbar, MainListContent, etc.) that can all be used together to create multiple mostly agnostic lists for business objects (eg. User... |
I am using Tablayout for an Activity in my app but for some reason icons for each tab using tabLayout.getTabAt(position).setIcon(icon) are getting small.
Additionally the text is always in uppercase. So I decided to implement custom views for each tab to get the desired result.
It did work but the code is not up to the... |
I have written a program to compare two 3D raw data equal or different. But I think the time consuming would be reduced if I use the STL. How to improve the program? The complete and varifiable code is showed as follows:
#include <cstdio>
#include <string>
#include <iostream>
#include <assert.h>
#include <cstdlib>
usi... |
I have made my first app in Elm, a lookup of Github users.
You type the name of the user into the search bar and the user's username and profile image - which has an anchor linked to their profile - appears below.
Here is my code:
module Main exposing (..)
import Html exposing (..)
import Html.App as App
import Html.A... |
This is basically my attempt to the German Tank Problem in which we are given a few serial numbers and expected to return an estimation of the total production count. Such as, if 4 tanks are captured with serial numbers 19, 37, 42 and 60, return the total number of German tanks there.
For a given number of serial numbe... |
I've written a simple multiple-sender multiple-receiver channel, but I'm unsure if my approach is the best way to do this. I'm not using multi-threaded primitives but instead wrapping around std's builtin sync::mpsc. Performance is fine so far for my use case, but I'm unsure how well this will scale given the fact that... |
Trying to create something really lightweight. Sources are on GitHub.
To create a proxy we need to define an interface first, e.g.:
// Fake Online REST API for Testing and Prototyping
[Site("https://jsonplaceholder.typicode.com")]
public interface ITypicode
{
[Get("posts")]
Task<BlogPost[]> GetAsync();
... |
So during my thesis I used xppaut quite extensively. In the end there were some minor problems and I decided to have a look at the code, which was just released at github.
So after 30 years of on and off development by Bard Ermentrout, it kind of showed some rough edges github link to xppaut, which I tried to smooth gi... |
Challenge
Swap the numbers surrounding the words in sentences.
Specifications
The first argument is a path to a file.
The file contains multiple lines.
Each line is a test case represented by a sentence.
Each sentence begins and ends with a number.
Print out the sentence obtained by swapping the numbers surrounding ea... |
Here is my solution for an exercise, which requires translation of strings to key presses on a phone keypad (for example, to get 'b' the digit '2' needs to be pressed twice).
It's taken from the book Haskell from first principles, and originally appeared in 1HaskellADay. I'd love to get feedback.
module Phone where
imp... |
The code reads 512 bytes at a time and stores them in a buffer. When the code sees a .jpeg signature it will proceed by writing to a .jpeg file until another signature is found, thereafter the process repeats.
#include <stdio.h>
#include <stdlib.h>
#include <cs50.h>
#define infile "card.raw"
#define BLOCK 512
/**
* ... |
I'm a beginner with rails working on a rails 4 project to use with my students. Users enroll in lessons; on enrollment, four activities are created for each user (expositions, scrambled, dictations, and spellings). Each of these activities has a number of words which are set to false in the db upon creation, and change... |
This class is part of the Construct library.
Container is a dict that:
turns attribute access into key access so con.a -> con["a"]
preserves the order of keys
I know, this is similar to collections.OrderedDict but it isn't available in Python 2.6.
For anyone preferring more interactive code, you can pull the trunk an... |
I had the need in one of my activies to handle displaying a message to the user when the network disconnected, and then reload the data for a RecyclerView adapter when the network reconnected to ensure it was up to date.
After getting that working for my use case, I wanted to make the implementation more abstract for r... |
I've struggled with this for quite some time. Today I finally wrote the following code.
The ViewModel contains an int property which later tells the view how many pages the data has been split into.
The controller splits the data by taking a specified amount of rows and, in the event of paging, splits by pageNumber * r... |
Please review my Queue implementation and let me know if you have any suggestions. I am not returning an exception for any of the methods defined here. As we know the exception is thrown only for add and remove functions and not for poll or offer functions.
public class QueueImplementation<T> {
private QueueNod... |
I recently answered a question that had an interesting problem statement (I've slightly modified the wording):
I have an abstract class A which is base for the other classes, let's
say B and C.
Classes B and C should have a handle_input() method, but
argument number and types may vary from B to C.
I also have a fu... |
As I was creating a CLI program, I realized having a ton of switch/if-then statements was a messy way to process user input. So, I set up a way to dynamically create commands as I added modules (Classes that extend the Module class) and methods. When a user enters a command like "sys::get bios" it gets passed to the lo... |
Please review my Deque implementation in Java and suggest ways of improving this.
public class DequeImplementation<T> {
private QueueNode<T> first;
private QueueNode<T> last;
private int size;
private static class QueueNode<T> {
private T val;
private QueueNode<T> next;
priv... |
This is a simple bash script (hopefully with a little style as well) for converting temperatures from Fahrenheit to Celsius and vice versa.
#!/bin/bash
re='^-*[0-9]+([.][0-9]+)?$'
while true
do
printf "\n\e[1;39mWhat is the temperature you wish to convert?\e[0m\n\n\t"
read -p "Enter a numeric value " n
w... |
I'm trying to create my own service, $hR. This service uses XMLHTTPrequest to get data from a URL with promise.
;(function(global){
var http = function(){
var self = {}
self.get = function (url){
var ajax = new XMLHttpRequest();
ajax.open('GET',url,true)
ajax... |
I'm writing the HTML for this website:
And this is the HTML I made:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Gustoso</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdnjs.cloudflar... |
Given I have a linked list, and I want to move a given node to the end of the list, is there a more elegant way of doing this, than what I've done here?
#include <stdio.h>
#include <stdlib.h>
typedef struct node {
int val;
struct node *next;
} node_t;
void insert(node_t **head, int val)
{
node_t *new_node = mal... |
Challenge
Given a list of numbers and a positive integer k, reverse the elements of the list, k items at a time.
Specifications
The first argument is a path to a file.
The file contains multiple lines.
Each line is a test case represented by a comma separated list of numbers and the number k, separated by a semicolon.... |
I currently have this monstrosity:
next_period = (((current_month + tax_period_months)-1) % 12) + 1
I want to get the month that is tax_period_months after the current month.
E.g. if tax_period_months=3, and current_month=09 then next_period=12
This works, but has that horrible -1 +1 to stop month 12 becoming 0
Any a... |
As the title states. I need a different type of icon for the different nodes types. at the moment I have this hacky way of achieving that.
for (var x = 0; x <= nodeList.Count - 1; x++)
{
if (xNode.Attributes["TYPE"].Value == "server.point.AV")
{
var tNode2 = new TreeNode(xNode.Attributes["NAME"].Val... |
My only concern with the following class is the line hierarchy.trimToSize() in determineHierarchy, because it is not necessary for determining the class hierarchy. However, putting it in the constructor clutters the code more than my current solution. Any recommendations or should I just live with it?
Since this class ... |
I am learning about reinforcement learning and came across the first and simplest form of reinforcement learning system called multi-armed reinforcement learning (also called as n-armed bandit). I have read Sutton's book and an outlace.com tutorial regarding this learning. Outlace.com has written a nice Python implemen... |
I needed to parse some command line switches from a string and I tried to do it the easy way so I just wrote this:
static class CommandLineParser
{
public static IEnumerable<string> ParseCommandLine(this string text)
{
if (Regex.Matches(text, "\"").Count % 2 != 0)
{
throw new Argume... |
I have to read from a file and store the data inside an std::vector container. The procedure of opening the file, reading and writing onto the container are enclosed in a routine: readData.
Reading and writing include the use of several std functions that may fail.
Instead of putting a try catch for each of those std f... |
Problem Introduction
You are given a primitive calculator that can perform the following
three operations with the current number x: multiply x by 2, multiply
x by 3, or add 1 to x. Your goal is given a positive integer n, find
the minimum number of operations needed to obtain the number n
starting from the nu... |
I understand there are a few similar tools available for testing speed but that's not what I'm looking for. I'm looking at seeing how long it takes to request a site's HTML. However, I'm getting slightly odd results.
The strange results are incredibly slow internet speeds so I'm confused about whether I'm doing somethi... |
This is a follow up from my previous post: Basic API wrapper around a Restful service
I'm writing a basic wrapper around a restful service that returns a list of Stores. Naturally, I want to make it completely testable (that's a major requirement!).
I have split out my TopmanClient class so that just deals with the res... |
I mostly just want to make sure I've understood the specs correctly with this code, but here goes:
var nums = document.getElementsByTagName('x-number');
var observer = new MutationObserver(replaceNumerics);
var config = { childList: true, subtree: true };
observer.observe(document.body, config);
replaceNumerics(); // i... |
I enter in the IMDb link and YouTube trailer link in the command line to a movie and the first main program loads all the info about the movie. The second main program uses an IMDb link to the movie and loads the actor's name and birthday.
Would it be better to write these programs as a class of some sort and use met... |
I'm trying to rewrite my old project in Reactjs. As I am a beginner and this is my first app, I need some assistance in understanding what is the best way to do this in the React way and how I can improve myself and this demo project.
Here is a working demo of it.
ListManager.js
import React, { Component } from 'react'... |
I need to create unique nonces for cryptographic purposes in a library that I am writing. If the nonces ever fail to be unique, the consequences may be up to and including remote execution of arbitrary code (by means of allowing injection of untrusted input into an unmarshalling operation).
While my particular applica... |
While extending the functionality of my polymorphic_callable<> type, I designed a way to obtain a result through a reader type that is set by a writer type; this is very similar to what std::future<> and std::promise<> do, but in a non-multi-threaded way.
Since that other question is already very long, I've decided to ... |
Challenge
Conceal a binary code within a word.
Specifications
The first argument is a path to a file.
The file contains multiple lines.
Each line is a test case represented by a space separated word and a binary code.
For each test case, print the binary masked word.
The mask alters the word according to the following... |
I am using below code to write list item to a file. I want only 2 fields from the list. Is there any direct way without looping through all the items to do that? Here serversToshutDown is a SharePoint ListItemCollection.
using (System.IO.StreamWriter file = new System.IO.StreamWriter("F:\test\Test.csv"))
{
foreach ... |
I have been using the following script for face recognition as a security feature:
main.py
from itertools import izip
from PIL import Image
def compare(self,pic):
i1 = Image.open("pic1.jpg")
i2 = Image.open(pic)
size = i1.size
i2 = i2.resize(size)
assert i1.mode == i2.mode, "Different kinds of imag... |
I gave myself a small project to work on and at first I wanted to use the MVC approach, but I got confused as to which part of my code should go into which class. I did some research and still don't quite understand how I should go about it.
This is the GUI I made:
I created the View class:
public class LevelUpView ... |
Currently I am using the gem activerecord-import to seed more than 55,000 records into my database, and it works fine. However, it takes too much time. I am wondering if there are any other ways to shorten the import time. Any suggestions would be appreciated.
ocean_routes_columns = [:origin_location_id, :destination_l... |
I had a task to create a VBA macros which will take a matrix data set with products in rows and persons as a columns (on intersection we have an ordered qty for each material for each person) and convert it into a CSV file for Advantix to load. As I'm new to VBA, I spent a couple of days investigating the forums and se... |
I am trying to implement a algorithm for the GCD of two numbers in a functional approach. Can this be improved further, also with regards to performance?
def gcd(a, b)
return b if a ==0
return a if b == 0
return b if (a%b == 0)
return a if (b%a == 0)
(a > b)? gcd(a, a%b) : gcd(b%a, b)
end
|
I'm working with some simple geometry problems featuring rectangles and circles. My code is as follows:
# Working with simple geometry problems featuring rectangles and circles
import math
class Point():
"""Represents a point in 2-D space."""
def __init__(self, x=0, y=0):
self.x = x
self.y = y... |
I am working on Django Rest Framework for backend to develop android app. My project is about Food Delivery System.
My app has user login and registration feature. I preferred oAuth2 for token based authentication. I did the user registration part. When a user registers, a new token is created for that user.
But I want... |
So, in my first attempt I created a code that generated all fibonacci numbers and appended to a list. This list I then traversed to get the even numbers and added them up. It worked, but took like 5 complete seconds to work.
Then I decided to not create a list and add the even numbers as I'm generating them. It looked ... |
I have created a program to search for a file in the computer. But I feel it can be improved. Can anyone help me with this?
filesearch.py
import win32api
import os
import io
from fuzzywuzzy import process
def filesearch(self,*args):
drives = win32api.GetLogicalDriveStrings()
drives = drives.split('\000')[:-1]
... |
I decided for educational purpose to make a generic sort like the one in the standard library as an exercise for my self in learning more about how to do generic programming in C and so I would really appreciate it if you guys could tell me how I could have done a better job and what other various improvements I could ... |
I'm working on refactoring some existing code to be a bit more extensible and am wanting to create a generic factory API for starting D3 charts.
Currently, my factory looks like this:
import { select as d3Select } from 'd3';
const protoChart = {
width: window.innerWidth,
height: window.innerHeight,
margin: {
... |
I have a c# application(mvc) that allows a user to upload an excel sheet containing an account number key and amount value to be passed as parameters to a proc that then validates those records, the proc then return an error or warning if any are found. My issue is that the BI team implemeted a proc which I cannot modi... |
In response to a recent SO question, I answered with the following code, and was wondering if anyone had any input on it. I'm always looking for an opprotunity to learn!
import java.util.HashMap;
import java.util.Map;
import java.util.Stack;
public class WordFinder {
public static void main(String[] args) {
... |
I've inherited a piece of legacy code that's pretty huge, and I've no idea how to go about breaking it into smaller pieces, and how to make the DB queries more efficient.
The project is built on a vanilla Python back-end with no ORM, hence raw SQL queries, the purpose of the function is to totalize the data of an insur... |
Today I didn't pass the test task for the position C++ junior/middle developer. What i did wrong?
Please help improve myself.
Task:
Description.
Write a template class - an array of any type of data, and tests to
demonstrate the work with this class. Should be implemented all the
methods also acceptable to exten... |
I wrote this queue object to handle async functions in JavaScript.
I'm not sure if this is a correct approach.
Is this steady enough to run on nodeJS or it may fail/fault?
var queue = {
callbacks: [],
start: function(){
this.returnVal = this.callbacks.shift()();
},
next: function(returnVal){
... |
I wrote this to calculate the diameter of a binary tree. Are there any cases for which this code might fail?
import java.util.*;
class Node {
int key;
Node left,right;
public Node(int item){
key=item;
left=right=null;
}
}
class BST {
Node root;
int diamet... |
I have a text such as
string text = "Hi [img-2] tst[img-3] test ttteessstt grawr[img-1-800]tet";
I want to find img tags in the text and get their id (second value) and possibly the third value if it exists.
string text = "Hi [img-2] tst[img-3] test ttteessstt grawr[img-1-800]tet";
var th = new TagHandler(null);
var... |
Re-use
Given that both the Langton's Ant and the Game of Life use a grid, I decided to code a generic grid_diplayer code and use it both for GoL (Game of Life) and Langton's Ant to put into practice the principle of code re-use.
Rules of Game of Life
Rules of Langton's Ant
Pure logic
The code inside the ant_logic and l... |
I am working on a batch file for doing date/time maths. One challenge is to determine the (proleptic) Gregorian year from the given number of days that have elapsed since day zero (that is, 1st of January, 0 AD, 00:00:00 o'clock), particularly when regarding leap years.
As per definition, a year is considered as leap y... |
This program tells me what lessons I have tomorrow then emails them to me.
This program works fine, but I was wondering whether there is a way to simplify the script or make it more efficient. I have removed my email and password and who it is to for privacy, but it does work.
import smtplib
import time
import datetime... |
I have been learning Java for a few months now and have created a basic calculator application in Android Studio for a school project. Since this is my first attempt at programming, I am sure that my code is not as succinct as it could be.
public class MainActivity extends AppCompatActivity {
double no1;
double no2;
do... |
This function accepts a String (either "right", "left","up", or "down") to do 4 similar but different things. I'd like a more elegant solution to this problem. I sense that there is one, but I can't think of it. Maybe by using a a few smaller functions? Maybe by using a dictionary?
private function addAndRemoveTil... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.