instruction stringlengths 71 71.9k |
|---|
I run a coding dojo at work. For one session I'm to showing that you can use a kata to get into a new language.
I'm using the FizzBuzz Kata to to show F# (and JavaScript) because it is short. The problem is I am very new to F# and find myself devolving to objects instead of being functional.
Thus, I would like to see... |
I've been working on this challenge for a week:
There are two sequences. The first sequence consists of digits "0" and "1", the second one consists of letters "A" and "B". The challenge is to determine whether it's possible to transform a given binary sequence into a string sequence using the following rules:
"0" ca... |
Below is the code snippet that I developed for ConnectionPool. Kindly let me know if there are any problems or shortcomings with the below code. I've deployed it to our test environment and was able to see that its not creating more the allowed MAX_CONN_CAPACITY and the objects are being re-used (I checked this by logg... |
I'm calling the below 2 function once per Cell in a table with over 135 columns and over 200 rows (that is 134*200 = 26800 times, I'm not running the functions on the first column).
I would like to optimize the functions as much as possible. Do you have any suggestions on how to do that, if it even possible?
this.addB... |
For the queries mentioned in link in 3 parts, the first two parts have been addressed, as mentioned below:
Part I (6 points)
list/DList.java contains a skeleton of a doubly-linked list class. Fill in the
method implementations.
Note: "node" is passed in these methods so that user of class DList can avoid slow \$O(n)\$... |
I know that there are combinatoric libraries for this kind of thing. However, with me being new to C# and coding in general I found that I couldn't understand the code well enough to implement it in my solution.
Here is the challenge:
Given two integers: L and R,
find the maximal values of A xor B given, L ≤ A ≤ B ≤ R... |
The problem
ConcurrentHashMap provides very weak consistency guarantees w.r.t iteration:
guaranteed to traverse elements as they existed upon construction
exactly once, and may (but are not guaranteed to) reflect any
modifications subsequent to construction
(note the "may" part).
In my case, I have a concurrent m... |
Let's say I have this form:
<form action="/user/store" method="POST" enctype="multipart/form-data">
Name: <input type="text" name="name"><br>
Male: <input type="radio" name="gender" value="male"><br>
Female: <input type="radio" name="gender" value="female"><br>
Photo: <input type="file" name="photo"><br... |
I have created a C# library that can send commands to a device and process the command specific responses and broadcasts over a serial port (or other communications method).
The library must also be able to handle request and response extensions held in other libraries as certain devices implement an extended command ... |
I'm currently working through Getting Started with EF5 using MVC 4 in Visual Studio 2010 (.NET 4.0) to learn about how to use ASP.NET and Entity Framework. During the beginning of the tutorial I ran into an issue with enum support when creating a database with Code First Migrations. For reasons unknown I have to work i... |
I tried to implement a queue which stores it's elements in a resizing array. Seems to work fine. Can you tell me if i did something wrong?
public class Queue<T>
{
private T[] array;
public Queue()
{
array = new T[16];
}
private void Enqueue(T item)
{
if(Count == array.Length/2... |
I am new to programming using the .Net TPL Framework and multi-threading in general. I have googled up some tutorials and articles and put together the solution below.
It is a simple multithreaded queue and a scheduler that polls the queue and processes each item as a seperate task.
It would be great if you'll can com... |
While fixing some old code I came up with a class that parses floats from a string.
This is used for parsing svg files in xml format. Floats can be separated by comma, space or anything at all in case the next number starts with a sign. They can also use exponential notation.
Sample:
<path d="
M245.792,247.275c0.82... |
In case you're not familiar with Knights and Knaves, it's a classic type of logic problem.
Here's an example:
"A very special island is inhabited only by knights and knaves. Knights always tell the truth, and knaves always lie.You meet two inhabitants: Zoey and Mel. Zoey tells you that Mel is a knave. Mel says, `Neith... |
I wrote a StringBuilder that works only with ASCII strings. the current append performance is almost identical to BCL StringBuilder append performance. I want some tips on how to make it faster, and general tips about the code. I did this for educational purposes.
Implementation:
public sealed class FastStringBuilder
{... |
I'm very new to Haskell, and I would like some feedback on my coding style. Is there anything here that could be made more elegant or concise?
This is my solution to Project Euler Problem 57.
It is possible to show that the square root of two can be expressed as an infinite continued fraction.
$$\sqrt 2 = 1 + \dfrac{1... |
And could you give me any security and optimization recommendations?
<?php
$datvariable = $_POST['comingover'];
$datvariable = htmlspecialchars($datvariable);
$datvariable = cleanPost($datvariable);
function cleanPost($item)
{ return mysql_real_escape_string(strip_tags(stripslashes($item))) }
$mysqliobject = n... |
I have written a code for a project which aims at finding the Cox regression coefficients in a mixed model for microarray data. The study was carried out on the Affymetrix Hgu133a platform. In the following code, I have first attempted to collapsing the probes to genes with the WGCNA package, and then carry out cox mi... |
I have a config.ini that contains my database credentials. I retrieve them with a parser class like this:
public function getField($section, $field) {
return $this->iniArray[$section][$field];
}
In my DbConnect class I do this, which seems silly:
public function __construct() {
$ini = new Configuration('config... |
I wrote a method that reduces a string like aabcccccaaa to a2b1c5a3
My implementation:
string Compress(string str)
{
StringBuilder builder = new StringBuilder();
using(TextReader reader = new StringReader(str))
{
while(reader.Peek() != - 1){
char c = (char)reader.Read();
int ... |
I'm working on this little text based game. Up to this point, I've gotten it to work, however I've heard I shouldn't be using global like I am. I have this set up to modify the global variables because I want the player to revisit a place and all the events have still been triggered.
I've just started programming, so ... |
My implementation:
string ReplaceAllSpaces(string input)
{
StringBuilder builder = new StringBuilder();
using(StringReader reader = new StringReader(input))
{
while(reader.Peek() != -1)
{
char c = (char)reader.Peek();
if(char.IsWhiteSpace(c))
{
... |
The following code has a modified version of the Breadth First Search algorithm. It not only visits the nodes, but keeps track of the paths, so I can output various messages later. I would like to make it more reusable and cut down on some of the duplicated code. There appears to be a lot of noise in it. Here are some... |
I need to handle C style ('\0' delimited) strings from/to a socket and came up with this as a first attempt:
#lang racket
(require racket/tcp)
(define (read-c-str inp)
(define (read-to-zero acc)
(define b (read-byte inp))
(cond
[(equal? b 0) (bytes->string/utf-8 (apply bytes (reverse acc)))]
[el... |
I'm just writing a small unittest to test for a hypothetical library and object, as a way of predefining the behavior, perhaps both as an acceptance test and for unittesting as well. As I'm writing this, I'm wondering about the value of BDD constructs.
import unittest
def pv(data, rate):
'''simple reference implem... |
My implementation of insertion, merge, and quick sort, with some utility testing functions. I just wanted to know how I can improve the efficiency and general cleanliness of my code.
(note: I know C++ has partition, but I want to do most of the implementation myself)
In particular, my main algorithms take iterators [fi... |
The following method receives a string and finds all occurrences of repeated substrings with a length of three characters, including spaces. Is this a good approach?
public Map<String, Integer> findOccurences(String str) {
Map<String, Integer> map = new HashMap<String, Integer>();
int counter = 0;
... |
I wrote this function to remove whitespaces in strings. Please help me improve it. I intended to use the function for a Big Integer ADT.
#include <iostream>
#include <string>
#include <string.h>
void rs(char* str){
int i(0);
int j(0);
while((*(str + i) = *(str + j++)) != '\0')
if(*(str + i) != '... |
I'm working on a primality test and have written a recursive function that returns the value of the function
\$b^{q-1} \bmod q\$
where \$3<= q <= 32000\$
Is there any way to speed up my function? It works, but takes a while to return the answer as \$q\$ approaches 32000.
Variables:
pow = \$q-1\$
mod = \$q\$
b is ... |
A few days ago I asked this question and I've got an answer to work with interfaces. I've tweaked around with this to get myself a INI parser class.
<?php
<?php
require "Parser.php";
class IniParser implements Parser
{
private $data = [];
/**
* Parses the data from a configuration file and stores it i... |
I'm starting on a new node/express backend and really want to keep everything clean and well tested. My previous project got a bit out of hand (in terms of test coverage and highly coupled code). So I'm going slow this time :-)
To be brief, this function currently sends a request to an API that responds with JSON data.... |
I have pasted a part of my event handler code block. I understand this code really looks like a mess specially the object that is created every time the message is changing. Is cleanup possible in this code? Any inputs will help.
btn.addEventListener('click', procs.debounce(bookDiningBtnHandler, 400));
var bookDiningBt... |
I've been wanting to revise what I knew on templated classes so thought I'd write a doubly linked list to practice.
It works fine, so all is well and good on that front, but is there something I've missed?
Current things I am aware of:
naming - could be a little more explicit
functionality - i.e. handling node* pointe... |
Previous question:
JavascriptObservable Storage
The idea is to have some storage interface that exists of different buckets - known as Eagles:
Eagle('bucket1');
Eagle('bucket2');
Every Eagle data is stored as Feathers.
var e = Eagle('fooEagle');
e.set('myFeather',{
'foo' : 'bar';
});
These Feathers can be observe... |
I'm using a many-to-many relationship between users and roles with propel:
<table name="user">
<column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" />
<column name="username" required="true" type="varchar" primaryKey="true" size="50" />
</table>
<table name="role">
<colum... |
I was interested to see if it was possible to implement an unsafe stack in C#, so I wrote this:
public unsafe struct Node
{
public int Value { get; set; }
public Node* Next { get; set; }
}
public unsafe class Stack
{
Node* first;
public int Count { get; private set; }
public void Push(int value)
... |
I'm currently toying around with some Computer Vision algorithms and always wanted to learn more about templates, so I came up with the idea to build a templated Image Processing Pipeline.
I want the pipeline to be built of several task blocks which I want to plug into each other sequentially. For a specific block, its... |
class Redirect {
public function __construct() {
}
public function to($key, $page) {
if(isset($page) && !empty($page)) {
header('Location: ?' . $key . '=' . $page);
exit();
}
}
}
With this class I can use this:
$foo->redirect('page', 'home');
instead of this... |
Version 1.0: Singly linked list
The struct and the prototypes of the functions were given in the question. I am unfortunately aware that this is more C code and less C++ code.
#include <iostream>
using namespace std;
struct node_ll
{
int payload;
node_ll* next;//Pointer to the next node
};
void print_ll (node... |
The program outputs a menu asking for a new question or to ask a question. If you ask a question, it will search a .tsv text file for the question and return the answer. It will then check a map that is used for time and date, if it exists, it will execute the function intended. If not, it will just print the answer. A... |
This is the fifth project in my CS1 class. It's a bit more drab than my past projects, so my titles are getting worse unfortunately. :(
Write a program that computes the annual after-tax cost of a new house
for the first year of ownership. The cost is computed as the annual
mortgage cost minus the tax savings. ... |
I wrote code using some kind of breadth-first-search algorithm in order to find a path (any path!) from a start point to an end point. There are no weights/different distances involved from path-to path-so I am not sure I should use Dijkstra's algorithm.
However, I am required to find a solution that can search for and... |
I have a project built with AngularJS and using Restangular in my services to handle API requests. The problem is I haven't found a good way to test the services which I think has turned into a bit of a code smell for me. I'm using callbacks in the promise to handle pushing the data back to the controller instead of ju... |
public boolean isNaN(String string){
@SuppressWarnings("unused")
BigDecimal bg = null;
try{
bg = new BigDecimal(string);
}catch(Exception e){
return true;
}
return false;
}
There is no native isNaN method for BigDecimal. The thing I don't like about this method is the suppressed warning. I never use the... |
Original question: Breadth First Search not SOLID enough
Here is my first attempt at refactoring. Instead of using a Tuple, I used a STRUCT and this made it more readable. I also extracted printing paths and finding paths into interfaces so someone could print their own messages or implement there own path finding al... |
I've written some code that allows Unity3D's inspector to display fields that conform to an interface. Unity has some quirks about their inspector, so as a preface they are listed here:
If you add a [Serializable] attribute to a class, Unity's Inspector will attempt to show all public fields inside that class.
Any cla... |
I don't really know how to explain what I'm looking for in a way that makes sense, but here goes:
Say I have a list
$$L=(4,7,9,10,6,11,3)$$
What I want to produce is a corresponding list
$$ K = (1,3,4,5,2,6,0)$$
where element K[i] has the value of the 'rank' of the element for the corresponding location in L. So the h... |
I wrote up a solution for the "Kindergarten Garden" problem on exercism.io.
My class will be handed a string that describes two rows of plants. Each student (either in a pre-set list or given as an argument) (sorted alphabetically) owns a 2x2 of plants. The method Garden.plants accepts a student name and returns a lis... |
I am going through the Coursera course The Hardware/Software Interface and because it has already ended, I would not be able to get any feedback on the code.
The assignment is:
LogicalShift: shift x to the right by n, using a logical shift. We can assume that 0 ≤ n ≤ 31.
I am wondering if shifting by n and then ba... |
I am fairly new to Akka and I am interested in any feedback about the following code. Is this the correct way to go about distributing workload across a number of threads? Do I use the Akka API correctly? Is this the right pattern for handling the routees exceptions?
package myakka.routing
import java.util.concurrent.... |
Inspired by Nested for-loop ASCII art, I looked at building a more complicated ASCII art than just the normal 'diamond' and 'triangle' variations that crop up occasionally here.
The challenge: Produce the following rocket
/**\
//**\\
///**\\\
////**\\\\
/////**\\\\\
+=*=*=*=*=*=*+
|../\..../\..|
|./\/\..... |
I implemented generic stack in C. Seems to work fine. It doesn't work for strings, though.
It was compiled using Visual C++.
Implementation:
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <string>
struct node{
void* value;
node* next;
};
struct stack{
node* first;
int elemSize;
... |
In this I have written the setAnalyticsInfo() method. The code inside this is common to almost all other (30) classes, so I have created GoogleAnalyticsCode and defined one common method and calling this method from all other classes.
import com.google.analytics.tracking.android.EasyTracker;
import com.google.analytic... |
I was working on a problem from Coderbyte. The challenge was to write a function that takes in a string and returns the longest word in the string. If two words are the same size then it asks to return the first one. The input will never be empty.
function longestword(str){
var replaced = str.replace(/[^A-Za-z\s]/g... |
Can someone give me some feedback on this pattern?
I am writing a node.js module that connects to a remote API, caches JSON, returns it as output. I have a cli wrapper script that uses the module, and then returns the output to a non-node app for a completely different purpose.
Am I using promises correctly here? Does... |
The following is a problem I found on this wiki. What can I do to optimize my algorithm, and make this code more C++11?
Write a program to discover the answer to this puzzle:"Let's say men
and women are paid equally (from the same uniform distribution). If
women date randomly and marry the first man with a higher ... |
We've got the basic functionality of using my postscript interpreter, xpost, as a library. I'd like to solicit some feedback from the community on the API setup. This example program, called xpost_client.c illustrates the API to rasterize a small EPS into a 792x612 BGR buffer, which it then dumps to a file as an ASCII ... |
Is there a shorter way of taking a dict with varying length lists and printing it to screen? Shortcomings of this method also include that values which aren't lists are printed as letters separated by spaces, and values which are numbers produce an error. Would it be better to write a class which could accept any type... |
I have done a WPF project and hope everyone can give suggestion for code refactor, especially for
UpdateErrorList() method within the MainWindowViewModel.cs
private void UpdateErrorList()
{
char[] targetChar = new char[] { '(', ')' };
errors.Clear();
for (int count = 0; count < _classes.... |
I am not very good a JavaScript, surely not date manipulation, but I hacked together the script below with the purpose to determine the next payment renewal date based on a start date and payment term. The script does what it is supposed to do. The script is part of a data transformation, which runs for every row in th... |
I'd like to check if the user submitted adress ip is a valid public IPv4 (non loopback, non local, non reserved).
For that purpose, I came up with that method, but I was wondering if this was enough or if I was missing some tests.
private boolean isValidPublicIp(String ip) {
try
{
Inet4Address address =... |
I'm learning PHP and currently object-oriented programming. I would like to get a feedback; how I'm doing so far. If I have bad coding that should be fixed immediately etc. I'd call this code an improved version. Because people said that my insert, update and delete methods were redundant. Do you think they're not redu... |
Using Rails 4 and a simple form, I'm rendering a couple of forms outside of their native controllers. Rather than scattering initialisers through my controllers, I wondered if it is cleaner to do the following:
<%= simple_form_for @event_submission || EventSubmission.new do |f| %>
|
Ok, I am working with 2 layers of class: somekind of a "manager" class which task is to take an object, link all items attached to it, and return it to the caller, and a "data" class which task is to call the database on a specific request.
Here's an example of how I work. Here's a "manager" class:
public class CardMan... |
The extension method:
/// <summary>
/// Thread safe. May lock on the input dictionary.
/// </summary>
public static U GetOrAdd<T, U>(this Dictionary<T, U> dict, T key, Func<U> create) {
U val;
if (!dict.TryGetValue(key, out val)) {
lock (dict) {
if (!dict.ContainsKey(key)) {
... |
I have a small assignment to read IP addresses and from a bunch of external text files identify which country the IP address comes from. I opted to use XmlReader and read the ranges from an XML file but unfortunately the performance has been quite abysmal (an average search time of around 7000 milliseconds).
Obviously ... |
My aim is to create a server control which inherits from a GridView and outputs the basic output wrapped in external markup, including other controls. For example, the output will look something like:
<div id="wrapper">
<div>
<asp:PlaceHolder id="summaryContent" />
</div>
<div id="gridViewWrapper">
<asp:... |
Following this question, I realized there is no built-in data structure like that, so I implement my own queue using List<T>.
Please comment on performance (is there any better way instead of using List<T>?)
public class MyQueue<T>
{
private List<T> _items;
private int index;
public int Count
{
... |
I had to write a function that calculates the percentage of values in table less or equal to 2. Is my code right or is there anything missing?
Public Function intPercentage As Integer
Dim intAge( , ) As Integer = {{0, 2, 5, 10}
{2, 0, 1, 3}
{5, 1, 0, 6}
{10, 3, 6, 0}}
Dim intRow, intCol As Integer
For intRow... |
I have written an algorithm intended to find prefixes and suffixes in arrays of strings.
I would like to get opinions/suggestions/reviews on the code I wrote (specially cases in which my code would fail), but also, I would like to know if this algorithm can be rewritten in a more optimal way since I will be running th... |
I have the following code, based on the input to the constructor I need to initialise some values which are wrapped in a simple POJO. These values are constant as you can see.
However I don't like the if/else construct in the set method and had read about NavigableMap as an alternative for holding range values. Any tho... |
Given a binary tree where each node has following structure, write a
function to populate next pointer for all nodes. The next pointer for
every node should be set to point to inorder successor.
struct node
{
int data;
struct node* left;
struct node* right;
struct node* next;
}
Initially, all next pointer... |
I have three divs that change a video link when they are hovered. I have the code working in three different blocks but I am not sure how to combine them since it is very repetitive.
$('#videolink-sd').mouseenter(function(event) {
//$(this).toggleClass('home-pager-hover');
$('.top-clock').stop( true, true ).f... |
It started with a simple log manager. Then I wanted to implement more features, for example printing the name of the component that send a message. Later on, I can think of giving each component that prints log messages it's own text color in the terminal and options to mute or solo single modules.
Therefore, the manag... |
I attempting to merge 3 functions into one, as they contain for the most part the same code.
Here are the original functions:
extern "C" PyObject *method_noargs_call_handler( PyObject *_self_and_name_tuple, PyObject * )
{
try
{
Tuple self_and_name_tuple( _self_and_name_tuple );
PyObject *self_i... |
The main problem the following query is solving, is the following:
Each Offer has multiple Odds (Odds has foreignkey to Offer). For each offer I want the latest Odds (ORDER BY time).
I'm pretty sure this is too heavy, so any input would be great.
SELECT "odds_odds"."id", "odds_odds"."offer_id", "odds_odds"."time", "odd... |
For practice, I've implemented my own smart pointer class. It's a 'unique pointer', meaning it doesn't allow copies of itself (when copying from a into b, a is 'emptied' after the copying, i.e. the raw pointer is set to 0), so there can never be more than one time where delete is called on the raw pointer.
It utilizes ... |
I've spent a couple days on my latest project, and I believe that I have achieved a sufficient level of efficiency to post it here for review.
The idea of the game is to mine out an "infinite" world of blocks by tapping on the screen. Objective-C (and Sprite Kit specifically) do not allow you to process a large number... |
I decided it would be interesting to simulate a game of Poker. Baby steps at the moment, and eventually I'll attempt to turn it into a GUI. The code I have so far is very basic such as populating a deck, shuffling the deck, and distributing two cards to a player. Trying to understand how inheritance works, the proper u... |
I am learning Python at present, from several books. I am new to programming and I need assistance with knowing when my code is written with good form and style - I want to ingrain the habit of writing good clean code, which would be accepted as thus by other programmers. This is a code example from the book Python Pro... |
I did a line-by-line translation and am wondering if the JavaScript code looks idiomatic.
Original Ruby code:
class Year
def initialize(number)
@number = number
end
def leap?
divisible_by?(400) || ( divisible_by?(4) && !divisible_by?(100))
end
private
def divisible_by?(a_number)
@number % a_nu... |
I am learning C++. This is a simple program I had to write for class. Is there anything I should fix?
#include <iostream>
using namespace std;
int main()
{
const int ListSize = 5;
int ValuesProcessed = 0;
float ValueSum = 0;
cout << "Please enter " << ListSize << " numbers" << endl;
while(Values... |
I am referring to the book Design Patterns For Dummies to learn about design patterns. I wrote an adapter design pattern, as mentioned in the book. Is it proper or does it need some modification?
#include<iostream>
#include<sstream>
using namespace std;
class AceInterface
{
public:
virtual void setName(string n... |
I have got the following function in my class that I think can be further be improved but I'm lacking ideas how:
...
private function populateAddressVars()
{
if (!$this->service_results || !$this->service_results->results[0]) {
return false;
}
foreach ($this->service_results->results[0]->address_co... |
I would like help in optimizing this calculation, which is from the Lazy Hobo Riddle:
There once were 4 hoboes travelling across the country. During their
journey, they ran short on funds, so they stopped at a farm to look
for some work. The farmer said there were 200 hours of work that
could be done over the ... |
bd is a bash script to conveniently jump multiple directory levels up from the current working directory instead of a tedious and possibly inaccurate cd ../../../..
Say, for example, that you are in the directory /home/user/project/src/org/main and you want to jump to project. Instead of counting the necessary levels t... |
This is my version of the knapsack challenge and I was wondering if there was a way to do it so it doesn't go through the foreach statement so many times. At the minute it goes through it thousands of times to get he closes value to the target number, which takes long time to do, I was wondering if there was a way to e... |
I need a simple prompt window to ask the user to do something with an OK/Cancel return. But I also need all Windows to remain functional, so a xx.ShowDialog isn't appropriate.
This is my attempt. DialogWindow takes a Delegate in the constructor and calls it when OK or Cancel is clicked with a True/False parameter resp... |
I made a function that merges nested tables into a single table.
The following function converts the headers. It takes an old table that has nested tables in its rows, takes all the headers of these and creates just one big table with one header.
This is only one part of all the creation for the new table. I basically ... |
I have a function where I validate emails via a regex. I was wondering if this is the best regex to use or if there's a better way of doing it.
Also is there a difference between this method and just setting the type="email" in the HTML form?
<form name="form" action="process_registration.jsp" onSubmit="return validat... |
I am using a public validating sub to help validate the other subs. Is this the most efficient way to do this?
Public Sub Validator(sender As Object, e As EventArgs) Handles GrossRevenueButton.Click, CPTCodesButton.Click, EstablishedVisitsButton.Click
Dim validater As Integer = 0 'this is the variable that gets sen... |
I'm currently building an application with the Microsoft Unity Framework. I also use a simple system of message publishers/listeners inspired from MVVM light and caliburn:
The listener interface
public interface IMessageListener<T>
{
void Handle(T Message);
}
The messenger interface
public interface IMessagePubl... |
I search for rails-like way of writing NodeJS code and it's more then hard to find the right way. The code quickly become bloated and unreadable. I would like my code to be as clean as possible.
Example (common ExpressJS middleware API controller):
var User = require('../models/user'); // mongoose model
exports.update... |
I have the following implementation, and hope to get suggestions on how to improve the code.
treeListViewModel.Courses is an observablecollection
treeListViewModel.Courses[i].Students is a dictionary
The code loops as follows:
List<uint> DataNotificationList = new List<uint>()
{
2,
... |
I have created a functional Caesar cipher in Python 3 and I have implemented a GUI using Tkinter.
def MOST_COMMON_LETTER():
return("e")
def circle(l,n):
if n < (len(l) - 1):
return(l[n])
else:
return(l[n % (len(l))])
def most_frequent(l): # not whitespace
l = l.replace(' ','')
all_... |
I wrote a small multiple select interface in jQuery, and I'm looking for any feedback on code quality/usability.
It has to do the following:
When check all is checked, all boxes must become checked
When check all is unchecked, all boxes must become unchecked
When all boxes become checked the check all box must become ... |
Since Hacker News launched their official API, I started working on Python wrapper for it. API v0 is fairly simple, you send a GET request with hacker news story's ID or user id, it returns data in JSON.
Here I do the same using requests library and return specific object like Item for news story or comment and User f... |
I have the following that works similar to forkIO, but returns a blocking "channel" that lets you receive the result of a forked IO computation. My main concern is its handling of exceptions. It will return Nothing if something is raised, but can't supply any more information then that.
I tried using try inside of wrap... |
As part of one of my AP Computer Science labs, I was required to write a function to determine whether a year was a leap year or not. Included as comments are a few reasons why I did things, as well as a more detailed version of the rules for leap years. Is there anything I could do better or have forgotten?
/**
* Re... |
I have a series of nested objects that I need to serialize into a byte (unsigned char) array to send out to another computer over UDP.
Right now I each object create a std::list, and pass that list to the next object up the 'tree' and then it merges the lists to create the final packet.
class Item {
unsigned char va... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.