instruction
stringlengths
71
71.9k
In this program I was required to calculate the Harmonic Average using an assembly program with a C driver. Harmonic mean is defined as: $$ \frac{n}{\dfrac{1}{x_1} + \dfrac{1}{x_2} + \cdots + \dfrac{1}{x_n}}$$ where \$n = \$ number of inputs and \$x_i = \$ a real number. I would like to know if: My code follows common...
I am working on a monitor signage display and have a "welcome to RSS" feed with just a title and description. I have code from feedEk that's been tweaked a bit to parse the feed and cycle it so I only have one title and desc. showing at a time. This feed could be added to or deleted info at any time so I need it to ref...
The code below is for calculating the minimal traversing distance from the top left point of the matrix to the bottom right point of the matrix. GitHub Here is the core functionality. Please note that y is a global variable keeping track of the memoization. def findLeastPath(matrix, row=0, column=0, path=[], sum_=0): ...
How to improve the functionality, exception safeness and other aspects of the following container adaptors? Allows to write more generic code (not working for, say, <set>): #include <utility> #include <iterator> #include <type_traits> template< typename container, bool = std::is_const< std::remove_reference_t< contain...
I wrote this code to append Maybe's: ghci> (:) <$> Just 5 <*> ((:) <$> Just 100 <*> Just []) Just [5,100] Similarly: ghci> (:) <$> Just 5 <*> ( (:) <$> Just 10 <*> ((:) <$> Just 100 <*> Just []) ) Just [5,10,100] Is this code idiomatic? Perhaps there's a more concise way to append a bunch of Maybe's together?
I am working again and got this to work. Is this the best way to write this code? $(window).load(function(){ var $window = $(window), $sticky = $('#contentSideIner'), elTop = $sticky.offset().top; $window.scroll(function() { $sticky.toggleClass('sticky', $window.scrollTop() > elTop); }); $window.scroll(function() { $s...
I am moving in to OOP PHP and having some problems extending my database class to my objects. I am still new to the variable scoping in OOP PHP, so if it a tiny syntax error I apologize. If my methodology looks wrong or can be improved, I would love to hear some feedback! class Database { /** Default Port is *...
Ideally I would have one draw method in the parent class (Player). But I can't figure out how to do this. I don't know if there is anyway to decouple it totally. I don't mind modifying the sprite sheet so that it can handle this sort of thing. Any tips are very welcome!! Both classes inherit from Player. var skeleton =...
In need for testing if a string is a number which could be a double or integer, I wrote a simple skeleton, which parses a string like this: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <errno.h> int main(int argc, char *argv[]) { char* to_convert = argv[1]; char* p = NULL; errno = 0; long val =...
I'm building a simple Poker game. It is almost complete, but I want to refactor it early. To calculate hand strength / ranks, I use this library from NPM: poker-evaluator For deck shuffling, I use the Fisher-Yates algorithm My code is mainly about game-play, determine if ready to start next round, determine whose tu...
I've been given the job of trying to reduce the line count for a file that helps generate a PDF for a web app. The class itself is pdfHelper, and contains a number of methods used to generate a PDF such as getting the location, custom methods for formatting lowagie.text table cells etc. I came across this particular me...
I'm a newbie in the use of LinqToXml and I wonder if I can improve this snippet. Shared Function GetListByType(ByVal intIndex As Integer) As List(Of FileInfo) Dim strWorkingPath As DirectoryInfo = New DirectoryInfo(GetWorkspaceDir) Dim lstAllFiles As FileInfo() = strWorkingPath.GetFiles("*.xml...
I have a performance problem when trying to create a csv file starting from another csv file. This is how the original file looks: country,state,co,olt,olu,splitter,ont,cpe,cpe.latitude,cpe.longitude,cpe.customer_class,cpe.phone,cpe.ip,cpe.subscriber_id COUNTRY-0001,STATE-0001,CO-0001,OLT-0001,OLU0001,SPLITTER-0001,ON...
Is there anything I can do to this code to optimize it to use less resources? write-host (get-date -format s) " Beginning script..." Add-Type -AssemblyName System.Windows.Forms do{ $len = [System.Windows.Forms.Screen]::AllScreens.Length; if($len-eq1){ $ie = Get-Process -Name iexplore -ErrorAction Silent...
I have a small project that requires a third-party module that's rarely updated (once every other year or so) and not maintained by any package management system. The context, here, is cognitive science & research, the third party module is for linking proprietary hardware to custom scripting, in the house project, pot...
The goal is to be able to call an event_<name> method on an object if it implements it, or otherwise do nothing, without needing to explicitly define and implement an interface for every event. The object may also forward the event to any sub-objects it has. Here is my current code: module eventobject; import std.type...
I have an array of objects. Whatever may be the size of this array, I need to ensure the size of the array as n using a default object. function fillRemaining(arr, n) { var defaultObject = {'id' : 0, 'name' : ''}; var temp = 0; while(arr.length + temp < n ) { var template = $.extend(...
I have the below code which increases the code complexity. Any way to refactor it? I am trying to refactor the below code so that the CCM can be reduced for the code. i.e code complexity matrix. //// TODO: Needs refactoring public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) { ...
This is my first website. I would like to make sure that: I am using HTML5 sectioning elements correctly. I didn't forgot anything important for HTML5 compatibility like html5shiv, for example. Any other advice? <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>DEdesigns</title> <scri...
A friend of mine and I recently started a project and at this moment we are writing a common library. He began writing an N-ary three and he is convinced that he has the best design with which I am not agree. I want to convince him, that his design of the N-ary Tree is very bad, and with this design we will face proble...
From OOP & OOD point of view, is it good idea to define Java-threads inside of the static method or in this case it's better to use instance-based method? public class ThreadPool { public static void stringAnalysis(ArrayList<String> strData) { Thread t; t = new Thread(new SentimentAnalysis(strData)...
This section of code reside in a utility class (LDAPUtility). It's purpose is to subscribe or unsubscribe a user from an LDAP group. My main questions are if I am using the LDAP library correctly and if I am handling the memory management correctly. + (BOOL)addUser:(const char *)userDN toGroup:(const char *)groupDN { ...
I'm learning to use iptables to implement it in my company software. The goal is either to prevent the major attacks and to have good speed transferring files (ssh and ftp). Can you help me to improve it or to discover errors? generic ip = 192.168.1.120 ethernet card = eth0 #!/bin/sh ################################...
This class should function as a simple insert into table. What do you think about it? How can I make my code better? class addProfile{ private $profileName; private $profileEmail; private $profileFromName; private $profileReplaytToEmail; public function __construct($profileName,$profileEmail,$profileFromName,$profileR...
I am trying to add an active class to my subnavigation using the waypoints jQuery. I am trying to avoid writing multiple functions to adhere to the DRY idea. The waypoints toggle the function based on their location in the markup. Any suggestions welcome. Markup <!-- top section --> <!-- waypoint class--> <a href="#...
I am writing a generic text parser and have come up with the following text parsing algorithm, which works fine. I'm wondering how to refactor the following method to make it easily understandable and maintainable for the future. It has chains of conditions and nested if-else blocks to compare with each text line to fi...
I am taking a C++ course and we have received our final assignment, I was looking for some suggestions and or tips so I can continue to improve. I am aware that the use of using namespace std is bad practice but my professor prefers that we use this way since it is a beginners course. The assignment was a two part ass...
When I read the community challange, I couldn't wait. So here I go with the very first Four tiles game: import pygame as pg import sys import random import time import tkMessageBox if sys.version_info.major == 3: import tkinter as tk else: import Tkinter as tk from pygame.locals import * def game(LENGHT): ...
We have a fair amount of code which looks like this: private boolean isThingChanged(String newName, Thing thing) { final Part part = thing.getPart(); if (part == null && newName == null) { return false; } if (part == null || newName == null) { return true; } return !part.getName(...
I want to know if this is a good idea. It is definitely only a proof of concept at this point, but if it's a good idea I would pursue the development into a more mature product. There are three main parts of this concept (maybe they should be separate questions, but I am asking about the concept as a whole and whethe...
I'm currently working on the library BigPicture.js with live demo here. There surely are lots of little improvements possible in the main .js file (< 300 lines of code), here are some little questions : Is it common to use something like : (function() { // code here } ) (); to launch the code and to be able that re...
This is just checking the parameter you enter is a neighbour of the current Cell (which is obtained using getRow() and getColumn()). Is there an easier way of doing this? How could I make this more compact and efficient? public boolean isNeighbourOf(Cell c){ boolean check = false; //check for not neighbours if(c....
I have a script for school that mimics the cp command. Part of the assignment is to modify the script so that the while loop (that assigns stdin to the variable filelist) is instead done with sed. The last argument needs to be saved to the variable to because that could be a directory depending on other user input in t...
I have a FactoryGirl page that generates same data but in two different languages. The variable names are the same. How do I write it in the smartest way possible without having to write a huge bunch of code? FactoryGirl.define do factory :static_page do language "" trait :purchase_loan do ...
The following is an implementation of the Alea random number generation approach by Johannes Baagøe, reworked from the rot.js implementation by dropping all the pesky underscore prefixes in the variables and making those variables truly private. The code has passed through JsHint and js-beautify, please address any and...
I've created a simple program that downloads an image (different image every day), then sets it as my desktop background. It is a console application, and closes immediately after downloading the image and setting it as my desktop background. It runs every morning at 6:00 AM via Task Scheduler. Although I have signifi...
I have an array like this (make sure you scroll to the right): [0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0] Where it will always be the same length. And there will always be some number of 0's surrounding some number of 1's. I am try...
My take on the Prebash Challenge, "Simon Says" game, in less than 300 lines of C++ (plus the header file), using SDL for window management and drawing. simon_says.hpp: #ifndef CR_SIMON_SAYS_HPP #define CR_SIMON_SAYS_HPP #include "SDL.h" #include <vector> #include <random> // ------------------------------------------...
I am learning C and I have some trouble with pointers. I decided to create a queue to practice a bit. The program works as intended, however I want to know some good practices and suggestions. Here is queue.c: #include <stdlib.h> #include "bank_sim.h" #include "queue.h" void initiliaze(Queue *queue) { queue->...
DataTable looks like below I would like to simplify this code in a better manner. DataTable dt = results.Results[0].DataTable; dt.Columns.Add("Averagedays", typeof(string)); dt.Columns.Add("0to3", typeof(string)); dt.Columns.Add("4to7", typeof(string)); dt.Columns.Add("Gtrthan7", typeof(string)); foreach (DataRow row...
Do I have basics of MVC and SOLID principles right in this simple 'Tic Tac Toe' game? View.java import javax.swing.GroupLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.WindowConstants; class View extends JFrame{ JButton[] knobs; JButton newGame; ...
I have just written something to guarantee a unique URL when creating pages within an old legacy system (sounds odd doing this retrospectively but we've just changed how the routing works). I don't often end up using while and I think this may be why I feel it can be improved. private string GetUniqueUrl(Page parentPag...
I was wondering if the following set up will return consistent result, i.e. no thread function call will be skipped. Also, is there any way to improve the threaded loop? Note the first loop is the multithread version and the results are out of order and this is okay but I was hoping to find a way to get them in order. ...
Previous question: Generate a random numbers class I have come up with three different ways to define type of mUniformDistribution. All of them work fine in VC++ 2013 and GCC. First approach by SFINAE: template<typename U > static typename std::enable_if< std::is_integral<U>::value, std::uniform_int_distributi...
I want to write a function which returns true if a selected date is smaller than the current date, else return false. This function is working as expected but I want to know the best possible way to do this. private boolean isValidDate() { if(year<yearCurr) { //selected year is small date is small ...
I have an MVC5 & C# application using the Razor engine. In my application I have a view, called "Index.cshtml". In this view I want to present a bootstrap modal to the user. When presented to the user, this modal will have buttons that should be capable of running JS functions and methods using jQuery. I have achiev...
Link to the challenge Given an input of \$T\$ rectangles, each of various dimensions \$l \times b\$, what is the minimum number of identical perfect squares that would cover each rectangle with no overlap or excess? Constraints \$1 \le T \le 1000\$ \$1 \le l\$, \$b \le 1000\$ Sample Input 2 2 2 6 9 Sample Output 1 ...
I know my way around jQuery and JavaScript a little bit but as for optimising, I'm a bit weak but willing to learn new stuff. I'm currently loading videos onto our site from Vimeo when a user clicks the appropriate image area. This is working fine, but I feel it's not an entirely performant way to go about doing it. D...
I wrote those examples to show different approaches to sharing results between threads. The whole code is on GitHub. All examples should return "Hello world". Are these OK from the perspective of data visibility? The most hardcore one: import com.google.common.util.concurrent.Uninterruptibles; import java.util.concur...
My non-serious entry for Simon Says. Based on literal interpretation of the rules: Create a UI with four colored buttons that light up in a random pattern. After displaying the pattern, the player must repeat the pattern by clicking the buttons in proper order. The pattern gets longer each time the player completes th...
I am trying a number as the sum of 3 squares. For my particular project I will require a complete list since the next step is to compute nearest neighbors (here). In any case we'd like to find \$ M = x^2 + y^2 + z^2 \$ in all possible ways. Here's what I wrote in Python: M = 1062437 m = int(np.sqrt(M)) x = np.arange...
I resolved to do the whole thing with just vanilla Javascript as a challenge, but man, Knockout's binding and state management is just too easy. A tiny bit of callback hell to get all the flashing / guessing synchronized, but what I'd really like people to look into is the OO-style of this. I try to avoid anemic models...
I have a very big Matlab simulation project in my hands, which I wanted to optimize, since I'm running it many times to tune parameters and the like. Using Matlab's profile I identified one function that is eating up most of my time, specifically the output(i,1) assignment line. This function is called a LOT, where inp...
I wrote a script to test how long it takes to make requests against a url. It takes a list of urls, an array of concurrent requests, and a number of times to attempt the test. How could I improve on this? //https://www.nuget.org/packages/RestSharp string baseUrl = "http://localhost"; void Main() { var urls = new...
I would like to know if my approach is correct and how could it could be improved? Also, is there a way to get rid of the relation between the Piece and the Board? At the moment, I am storing the position of the piece both in the piece and on the board. Is there some way to change that? I have considered a Game to cont...
I've managed to create a function to pipe the stdin, stdout and stderr of a child process and provide them as file descriptors to read and write to: pid_t opencmd(pipes, path, argv) int *const pipes; const char *const path; char *const *const argv; { if (!pipes || !path || !argv) goto error_in; ...
I'm representing DB tables as classes (in this case PHP classes). This has the goal of modeling every section of the web page, where you will get inputs from the user. My actual base design is: One class per table and every row is represented by an Object of this class. The constructors asks for what they need in ord...
I have come up with this approach but I'm not convinced about its effectiveness. Is there any effective approach? #include <string> #include <iostream> template <typename Container, typename UnaryPredicate> auto remove_if(Container& c, UnaryPredicate pred) -> decltype(c.begin()) { auto it = std::begin(c); ...
I'm kind of newbie for these things but I did something and I want to know how I can do this effectively. import java.sql.Connection; import java.sql.Statement; import java.sql.ResultSet; import java.sql.DriverManager; import java.sql.SQLException; import java.util.Random; public class BankingApp { public static v...
I wanted to ensure that lastActivityTime is always the "latest" value based on current time, but I wonder if my "update" method is thread-safe? If it's not, what's a better solution besides just throwing "synchronized" around. import java.util.concurrent.atomic.AtomicLong; public class Widget { private AtomicLong...
I am using MVC 4.0/C#/EF4.0 and I have a grid page that grabs results that are filtered, sorted and paged. It's filtering results from a table that has 45,000 records. How do I improve performance? This page takes over 30 seconds to load. var filteredresults = _unitOfWork.ModifiedDataRepository.Get(); Na...
Interview question some engineer, asked me to write binary search in 2 ways, Also asked me to write binary search on a shifted array (10 20 1 2 3 4). Wrote that and then asked me to find the offset of the array in log n. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System...
I'm learning about control structures now, and I want to see if I'm doing this as cleanly and efficiently as possible. Seems like there should be a less... verbose way of writing the switch but I wouldn't know what it is. Any criticism welcome! FizzBuzz.java public class FizzBuzz { public static final int fizz = 3...
I cooked up this little game today for the community challenge mentioned here. The idea of the game is that sometimes when Simon gives you a color, you should choose the opposite color (the color in the opposite corner). The game visually indicates this when it is an Opposite Simon. I'm not totally sure that the gam...
Here's a little game written in HTML5 using bleeding edge audio. Since I don't do much HTML5 or Javascript, I'm particularly interested in: Structure Is this a reasonable way to structure the Javascript? Should I encapsulate everything in an object? Compatibility I believe the older versions of Internet Explorer won...
I was creating a Rails form where users have to enter their state. I ended up creating a select tag which is really, really ugly. I'd like to think there's a better way of writing this. <p> <%= f.label :state, "State:*" %></br> <%= f.select(:state, [['AL', 'AL'], ['AK', 'AK'], ['AZ', 'AZ'], ['AR', 'A...
I'm currently learning Clojure, and am working through a few exercises. The exercise that I'm working on right now is accept an arbitrary string and determine if the opening and closing parenthesis, curly brackets, and square brackets correctly nest and line up to each other. For example, "hello { ( world ) } []" would...
My main concern is how messy the min-number-of-slices function is. I would appreciate help finding good ways to clean that up since it has a lot of nesting/scope. This is my first ever Clojure program, so I know this is probably not idiomatic Clojure, nor is it neat, nor probably fast, either. Please give as much fee...
I am using the below code to merge two images, but it take avg of 6-7 sec for creating 16 images. Is there any way I can speed up my process? $image1=imagecreatefrompng('img/'.$value); $image2=imagecreatefrompng('img/'.$value1); $w=imagesx($image1); $h=imagesy($image1); imagecopy($image1,$image2,0,0,0,0,$w,$h); imagejp...
I have a slideshow in jQuery slideshow switching picture automatically every 5 seconds with CSS3 transitions. The current picture has the current class, the previous picture has the forrige class and the next picture has the neste class. The first picture on page load has the first class to avoid animation, and a bakle...
I have to implement a "filter" in a Excel file which deletes/shows particular strings found in specified columns. I save the rows numbers that have to be deleted in a list. I have my filters in several dictionaries containing a list. The column index is mapped to a list containing every string that has to be filtered (...
Enough with imprecise floating point datatypes called float anddouble. I present to you Rational. Of course, Rational number arithmetic is easy, so I took up a much more interesting challenge: Rational Number Approximation. This is what I have implemented in my code. I have employed a technique similar to binary searc...
I have an assignment for which I need to write an AVL tree. This is what I have written so far. It works on all of my tests, but suddenly fails in checking system with TL (time limit exceeded). Personally I think there could be a bug with input data in test (although I have already solved this problem with Cartesian tr...
I have spend quite some time now to find out how exactly to do socket programming in Swift (Xcode 6.1). There are a few examples out there, but most of them no longer work for the latest release of Swift. Finally I came up with the following (see below). That seems to work, but I am not 100% certain that it is fully co...
A class for notes calculation. #!/usr/bin/env python3 from string import ascii_uppercase class Notes: notes = ascii_uppercase[:7] notes_number = range(7) notes_dict = dict(zip(notes, notes_number)) numbers_dict = dict(zip(notes_number, notes)) def __init__(self, _note): if not _note in N...
I've implemented the Sieve of Eratosthenes algorithm in Haskell. Please take a look. Any suggestions are greatly appreciated :) import Data.List -- a list identical with {seq} but for multiples of {p} which are replaced by {-1} sieve_once :: [Integer] -> Integer -> [Integer] sieve_once seq p = map (\x -> if x `mod` p ...
Version 2 of Music note class #!/usr/bin/env python3 from string import ascii_uppercase from string import ascii_lowercase class Notes: octave_number = 7 low_notes = ascii_uppercase[:octave_number] high_notes = ascii_lowercase[:octave_number] notes = low_notes + high_notes notes_number = range(oc...
I was asked to implement a graph and BFS and DFS. Please comment. Is it understandable? Is my algorithm correct? Are there any optimizations? using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication2 { public class Graph {...
I was given this piece of code, which calculates the length of the longest string in a vector of strings: static size_t max_line_length(std::vector<std::string> &lines) { size_t max = 0; for (auto it = lines.begin(); it != lines.end(); it++) { if (it->length() > max) { max = it->length(); ...
I have written a jQuery function that is doing an auto complete look-up and then building the form for me. This is working fine but I want to reuse the code so I can have the form rebuild after submitting the data to see the results. Here is the basic html and jquery script below. Right now the form is doing the look-u...
I'm looking for a more consise way to sort a block of objects. Where you can sort a block of blocks based on the numeric position of the values to compare, there's no such shorthand for comparing objects by a given field: test-data: reduce [ object [name: "A" value: 1] object [name: "B" value: 3] object [na...
You have two lists with meetings scheduling (start time, end time). Meetings in single list don't intersect. Find all intersecting meetings across the two lists. Is my complexity \$O(N M)\$? If I use binary search I might get \$O(N \log M)\$. Can you think of a better algorithm? For simplicity, I didn't use DateTime....
I have a page that is part of a CMS and I cannot alter any existing HTML or CSS, but I can add additional custom JavaScript and CSS. There is some text on this page I want to hide and I found a solution but it feels kludgey. I can't be sure other pages won't have similar content on them, which is why I'm being so speci...
This is how I am deleting a node from a singly linked list. Would this be the most correct way? void Remove(Node** head, int value) { Node** ptr = head; while (*ptr && (*ptr)->data != value) ptr = &(*ptr)->next; if (*ptr) { Node* next = (*ptr)->next; delete *ptr; *p...
This is my first time messing with non-rectangular windows and animations in WPF, so while I'm working on all the bugs I'm having with the actual game code, I'm submitting the XAML for review - I don't like how redundant it is, but I'm sure there's a clever way to simplify it. <Window x:Class="SimonSays.MainWindow" ...
I have had little experience with OO programming, being a typical engineer I tend to hack together functional code. However, I'm trying to change that and I see value in implementing OO when modelling the physical world. I've written my first ever class for a position vector. I want an instance of the class to be able ...
This gives you one note and asks you go up or down the scale for a certain number: /////////////////////////////// //// ClearConsole.java /////////////////////////////// /** * Created by IDEA on 06/12/14. */ public final class ClearConsole { static void clear() { StringBuilder stringBuilder = new String...
I created a short Perl 6 script copyfnameascii.pl to copy a file hierarchy I have, applying an URL Decoding to the names of folders and removing non-ASCII characters from the names of files. $ cd workingdirectory $ perl6-m ../copyfnameascii.pl project copy It is best illustrated by the following diagram: ...
This is the following Python code that I have coded for an algorithmic problem online. For each line of input, the goal is to find the greatest number of repeating blocks into which the string can be split. For example, if the input is abcabcabcabc, then the output should be 4, because the string is equal to 4 repeti...
Would switching my cuts below to SED improve performance? I am trying to get a per date count of requests for the last two weeks from a server log. The script runs, but slowly (comes in around 14 minutes). The file is 8,867,820 lines long and around 1.9G. I would guess grep, SED (or AWK) would do this more efficiently ...
This definition is taken from Wikipedia: A pangram (Greek: παν γράμμα, pan gramma, "every letter") or holoalphabetic sentence for a given alphabet is a sentence using every letter of the alphabet at least once. Pangrams have been used to display typefaces, test equipment, and develop skills in handwriting, calligraphy...
This is how I'm currently escaping MySQL strings in C++: std::string escapeSQL(const char* dataIn) { if (!MySQL_Database_Connection__global->host) int a = NULL; if (dataIn) { std::size_t dataInLen = strlen(dataIn); std::string to(((dataInLen * 2) + 1), '\0'); mysql_real_escape_string(M...
I've been working on a simple Tic Tac Toe game in JavaScript. It runs the way it should, but the Board.checkWin function (check every possible winning combo) could be better, it is very repetitive in its current state. Any ideas? Here is my Cell class: var Cell = function() { this.value = "|_|"; }; Cell.prototype.se...
I'm learning Haskell, and one exercise was to implement squashing of identity-multiplications, e.g.: \$5 + (2*1) => 5 + 2\$ Here is my implementation: squashMulId :: (Ring a, Eq a) => RingExpr a -> RingExpr a squashMulId (Mul x y) | x == (Lit (mulId)) = squashMulId y | y == (Lit (mulId)) = squashMulId x ...
I'm doing some challenges to learn new and interesting concepts, this one is about a Lights out variant, instead of toggling only the adjacent tiles, it toggles the whole row and col. It must be solved in pure python, so no numpy or other libraries that might help are allowed here. I adapted the algorithm of this excel...
I'm working on a simple parser that is supposed to extract hash maps representing vinyl records from web pages (online stores) and XML files. The goal is to have a parser that I can easily run with multiple threads over a ~8 MB XML and a ~2 MB HTML file to read products into a relational database. I know the relational...
I've recently been introduced to SFINAE to solve the problem of unwanted promotion precedence. i.e. I was hoping to catch integer types with Foo::Foo(long) and floating-point types with Foo::Foo(double), but alas int -> double rather than long. /* Constructors for various types, for example, 'Object{"foo"}, Obj...
I made this to help new techs be more proficient while they are learning. I know most of it is common knowledge around here. I would also like to point out that I don't really know batch but I am learning. Feel free to copy, share or contribute. This should work on XP, Vista, 7, 8, 8.1, and 10 but it's not 100% tested ...
I'm writing an interpreter for a scripting language which allows objects to: Have an alias Be referenced using a wildcard Contain child objects Combination of all three above For example: CreateWindow("win", ...); CreateName("win/texes1", ...); CreateName("win/texes2", ...); CreateAlias("win/texes1", "wintexes"); Cre...
Ok, it's not completely like Simon Says, since it's text-based. There is nothing about memorizing based on visual cues and/or sound here, just memorizing long sequences of numbers. I wanted to do it in the language I write the least code in, Scheme (w/ Chicken), and see what happens. (use posix) (use (srfi 1)) (define...