instruction stringlengths 71 71.9k |
|---|
The problem goes like this.
Change the strings provided by user to form palindromes. To do this, 2
rules are:
(a) Reduce the value of a letter, e.g. Change 'd' to 'c',
but cannot change 'c' to 'd'.
(b) In order to form a palindrome, you
can repeatedly reduce the value of a letter until the letter becomes
'a'. Once a l... |
This is the most Monadic code I have written to date :-) and I'd welcome comments.
I'm also struck how much faster this mutable approach is than the immutable version I first wrote (see end). OK, so QuickSort is pretty much on mutability, but most algorithms seems to involve significant manipulation of elements in the ... |
I am simulating a bridge where only one car can cross at a time. The bridge runs north south. The car arrival times and times taken to cross the bridge are given in an input file. The format is direction|arrival time,time taken to cross. The possible directions are north and south, represented by N/n and S/s respective... |
I have this query where I am working out the percentage of peoples occupation. I have a sub query that works out the total count of people codes and that result is what I used to divide by. I could hardcode this but the count could change.
It just looks a bit messy and I am wondering if there is a nicer way to do the s... |
I have to refactor this method: it seems to duplicate two code blocks with some slight variation. Any suggestions? It is a bit of a mess :)
public EstimatedAttitude estimate(int numStars, Double2d starsBrf, Double2d starsMeq, Long1d starsIdsForRange,
double measerrRef, double probThresh) {
Double2d starsBr... |
CPLEX is a solver for mathematical problems made by IBM, and it offers callable C libraries.
My usual project configuration is a main.cpp file will all the important code and a simple cpxmacro.h file with some macros. Sometimes there are also .dat files with problem data. When the solver does its job (i.e. the main is ... |
My Implementation:
string NumberToEnglish(long n)
{
StringBuilder builder = new StringBuilder();
var trillion = 1000000000000;
var billion = 1000000000;
var million = 1000000;
var thousand = 1000;
var hundred = 100;
while(n != 0){
if(n >= trillion){
builder.AppendFormat(... |
I wrote an email syncing program in my ASP.NET MVC website that syncs e-mails from multiple e-mail accounts to my database.
Each e-mail account has to be independent from other accounts and they have to run asynchronously.
Are there are any issues with my code such as efficiency, bugs or can there be made improvements?... |
I'm working on some simple console game and I'm starting to get stranded in my modelling. There is some fragmentation and tight coupling going on!
In this version I would just want to be able to move my paddle over the screen (but this needs to be extended to multiple players, ill get back to that later).
This paddle ... |
My code, which generates Cartesian product of all lists given as arguments:
public static <T> List<List<T>> cartesianProduct(List<T>... lists) {
List<List<T>> product = new ArrayList<List<T>>();
for (List<T> list : lists) {
List<List<T>> newProduct = new ArrayList<List<T>>();
for (T listElem... |
I used the example on here, but with little changes in order to write a base64 encoder method. I have a few points about the code:
I would like to use using statement, but I do not want to use inner "using" statements, so I use multiple variable declaration in a single "using" statement. Is that suitable in order to b... |
I'm still learning PHP OOP, so I'd like to seek for some expert advice or criticism regarding this code I created.
In this script, I created the objects I need to process the user input from a form. While the $homepage object is responsible for displaying the whole webpage.
My questions are:
Is this consider clean cod... |
I have implemented a class that has a method to wait until "something else" has happened. When this has happened, the current thread stops waiting and returns from the method. This is my current code:
public class InMemoryAviReadyNotifier implements AviReadyNotifier, MessageListener<UrlAviMessage>
{
private Map<Sou... |
I'm new to Python, but have a lot of experience with C and C++. I would appreciate some feedback on my implementation of a packer for this archive format. Specifically, any feedback on how idiomatic this code is for Python, and any suggestions about the algorithm used.
VPK is a relatively simple uncompressed archive fo... |
I have a function that takes all items in a queue and increments their order (used to allow insertion earlier in the queue).
private function incrementAllQueueItemsWithOrderLargerThan($order_larger_than) {
return $this->queue()
->where('order', '>=', $order_larger_than)
->increment('order');
}... |
So let's take this code which increments a Javascript text field value:
<div id="counter">1</div>
var counter = $(".counter")
counter.html( parseInt(counter.html()) + 1 )
It can be made shorter by using the Unary operator + which behaves like Number():
<div id="counter">1</div>
var counter = $(".counter")
counter.html... |
For practicing purposes, I created an application that attempts to find an optimal route between given points.
The algorithm is:
Connect two randomly selected points
Select a point that's still unconnected (let's call it A)
Find it's nearest connected neighbor (let's call it B, where C => B => D)
If the distance C => ... |
Finally, Parameterised Constructors are possible in VBA.
Background:
One rainy day, I came up with an idea: take a static class and expose one property as default (like it was done in the Reverse for each loop for the .Item() property. This time however, I thought I'll make a PieceOfMe() Get Property the default which ... |
The goal for this project was to:
Write a program that continues to asks the user to enter any number other than 5 until the user enters the number 5.
Then tell the user "Hey! you weren't supposed to enter 5!" and exit the program.
★ Modify the program so that after 10 iterations if the user still hasn't entered 5 w... |
I have the following wx.Window:
class SketchWindow(wx.Window):
def __init__(self, parent):
wx.Window.__init__(self, parent, -1)
self.SetBackgroundColour('White')
# Window event binding
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.Bind(wx.EVT_IDLE, self.OnIdle)
# run
self.Run()
def OnPain... |
Visual Studio 2013 still doesn't support the alignas keyword in C++11. This causes some problems with alignment of types in various situations. Thankfully the compiler will generate an error when it can't guarantee the alignment or at least give a warning.
To solve these errors and warnings I'm implementing a wrapper ... |
While solving a problem from HackerRank, though it's an easy one, I wrote this big program. Not sure if recursion is applicable and hold good but to me it looked like it isn't. However when I run the program I see my code executed fairly well.
Here is the problem statement ("Sherlock and The Beast"):
Print the largest... |
In my previous Watir question I was making a module with session_FF accepting a block.
Now I want to make the same but via RSpec. Here is my try:
require "rspec"
require "watir"
module Session_FF
def method_missing m, *args, &block
@browser.send m, *args, &block
end
def element *args
elements = @browser.... |
I have this Image class that I've been using for some time now on personal
projects and games I eventually write. It was written in C++98 style and it
is starting to show its age. Over time, I added a few C++11 elements here and there,
but I think it is now due for a major refactoring.
image.hpp:
#ifndef IMAGE_HPP
#def... |
Can this method be improved?:
public static Session getHibernateSession() throws SQLException{
synchronized(dbSessionMutex){
if(session == null || !session.isOpen()){
session = HibernateUtil.getSessionFactory().openSession();
}
else{
final SessionFactoryImplementor se... |
I have several buttons and I want to toggle between them like radio buttons.
The way I have it set up now is that each button have this same code but the buttonValue varies depending on which button they click on.
ToggleButton one;
one = (ToggleButton) view.findViewById(R.id.number_one);
one.setOnClickListener(new View... |
I have an SSIS package for SQL Server 2008. In this package, I need to verify that a file exists that matches a pattern of SomeFileName_*.txt where the wild card replaces a YYYYMMDD date. It doesn't matter what the date of the file is, just that any file matching that pattern exists. If a file does not exist, I need to... |
Are there any pitfalls in changing the prototype of the String object? I'd like to change the word substr to "left":
String.prototype.left = function(n) {
return this.substr(0,n)
}
Is this ok, or should I just get over it?
Next, I'm going to write a .right(), a .mid(), a .val() and a .int().
|
Project Euler Problem 27
Euler discovered the remarkable quadratic formula:
\$n^2 + n + 41\$
It turns out that the formula will produce \$40\$ primes for the
consecutive values \$n = 0\$ to \$39\$. However, when \$n = 40, 40^2 + 40 + 41 =
> 40(40 + 1) + 41\$ is divisible by \$41\$, and certainly when \$n = 41, 41^2 ... |
I've made a simple program that moves the mouse and do other silly stuff. I want you to look at it and tell me what can I do better/less space and also what can I add. I want to prank my friends.
#include <cstdio>
#include <windows.h>
#include <conio.h>
#include <tlhelp32.h>
#include <iostream>
#include <time.h>
#inclu... |
I've semi-often been frustrated at the lack of a proper Matrix data structure in VBA. A multi-dimensional array is obviously the right way to handle it, but there is so much missing... for example, you can't natively check to see if an array has been dimensioned, you can't resize the array while preserving values excep... |
I'm new to ruby, later I asked about ways to refactor code (Parsing GPS data), one man gave me direction, so I made class for Median filter and it will be great to read review for my work.
What guys are you thinking about it? Is it still smells?
class MedianFilter
attr_accessor :step
def initialize(step, keys)
... |
I was writing a bit of code and I was just wondering if I was doing it the right way. I know all the syntax is right and It all works perfectly. I was just wondering if I'm doing it the right way. Should I have another infrastructure, am I following the MVC correctly (there is no V yet, it's mostly just a model). Is th... |
Wrote this class it allows me to connect to database and display as many columns as I wish to. I can just give it desired parameters and I'm done. I've commented about the parameters that need it to be passed.
include('connect.php');
//include this file. This is our class
$connection = new connection_to_db;... |
I'm very new to coding and I've attempted to make my first website, however I feel as though I haven't coded it with a proper structure.
Here is one HTML page from my website, along with the CSS that is common to all pages. I've also made a jsFiddle of it.
/*CSS FOR ALL PAGES*/
/*ID SELECTIONS SECTION*/
/*BODY/WRA... |
I am working on a simple SDL game in C++. I want to make my collision detection implementation better.
Here's the complete project:
#include <SDL.h>
#include <SDL_image.h>
#include <cstdio>
#include <string>
const int SCREEN_WIDTH = 512;
const int SCREEN_HEIGHT = 512;
bool initialize_game();
bool load_game();
void cl... |
I'm running hundreds of curl operations in parallel to my own API, the response array that I get is out of order (the reason being that the first one to finish gets added to the response array first). I need to sort these back so they correspond to the input array, in order to do that I have already written a function ... |
I'm working on a system that can search for similar images. This involves being able to search by edit-distance, and as such I've implemented a special data-structure called a BK tree. Some notes here.
The core idea here is to be able to search for items by edit distance, in this case Hamming distance between discrete ... |
I am parsing a table:
|-------|
|Bar|Foo|
|-------|
| 5 | 6 |
|'f'|'g'|
| 1 | 8 |
|_______|
I've tried a number of ways of writing a pick function in Python:
#!/usr/bin/env python
from collections import OrderedDict
def pick0(r, k):
Bar, Foo = r
return locals().get(k)
def pic... |
I never really bothered using mod_rewrite to achieve SEO friendly names but I've always admired from a distance because I've never been good at regex.
The below .htaccess file does work, but I'm sketchy about all of it and maybe I've structured it incorrectly, furthermore it looks terrible and I know that I'm doing it ... |
I have working code that gets product details and config values from a MySQL
database, but it's combined with HTML. Is there a better way to do this, maybe a class that I can use?
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-i... |
We don't have the possibility to install modules like psutil on some boxes, thus I decided to write a simple script to calculate the CPU percentage by the given PID.
It uses /proc/stat to get CPU times and /proc/<pid>/stat to get the process CPU usage.
I added top output here, just to compare results and to be sure it'... |
I've made my first-ever program in Go, which sorts a given input of integers. There are 2 options: The list of unsorted integers and the algorithm to use.
Since it's my first go project I'm a bit unsure of a few things. For example, the "floating" variable declarations.
I think that the algorithms itself are okay, th... |
I have a model of the solar system that I'm working on at the moment. Now is the time to start cleaning my code up a little.
Here's what I have so far:
A main 'driver' method:
public class SolarModel {
public static void main(String[] args){
SolarSystem model = new SolarSystem(700, 700);
/* Create new inst... |
I have about a hundred Rake tasks that are creating Rails models for me from a legacy datafile. Each task shares some setup and teardown code; all that sets them apart is the code in the middle. For example:
task countries: setup do
rows = rows_from_file("system/countries", 2)
bar = RakeProgressbar.new(rows.length)... |
I have my reasons not to use the ASP.NET membership. Though this causes me some issues. I read about a thousand articles on ASP.NET MVC custom authentication and I've found that almost all of them are just too simple to be of any use.
What I need is a good way to login a user, keep some info about him securely in a coo... |
This question is about reducing the size of files saved to disk in an infinite world 2D mining game.
I finally added code to my game to save and load distant chunks instead of keeping all of them in memory. Up to this point, I had only used the default NSCoding Apple library to save and load files from disk. In my ... |
This is an implementation of a function to check the property of a Binary Search Tree, that is:
the key in any node is larger than the keys in all nodes in that
node's left subtree and smaller than the keys in all nodes in that
node's right sub-tree
I'm looking for reviews on code correctness and test cases.
publ... |
I'm working on a project with Flask and I'm trying to follow Miguel Grinberg's Flask tutorial as closely as possible while creating what I need for my own project.
Overall, how does it look? Miguel's models were relatively simple and since mine are so complicated, I'm not sure if I'm doing it correctly. I tried to norm... |
Based on this question (but fixed so it can run).
I have kept the code as close to the original as possible.
I have Marked all the changes with Loki (should be easy to spot).
Code here is written in the style of the original author.
Dic.h
#ifndef DIC_H
#define DIC_H
#include <iostream>
#include <string>
using namespac... |
I have this universal error handler for my HomeKit app (currently in development). It grew out of wanting a single place to write error messages, show alerts, etc. I wanted a short, simple way to call it from anywhere that may generate an error.
Here's the class:
import UIKit
import HomeKit
class ESErrorHandler : NSOb... |
I was trying to solve problem 5 of Project Euler, and this was I needed to do:
2520 is the smallest number that can be divided by each of the numbers
from 1 to 10 without any remainder.
What is the smallest positive number that is evenly divisible by all
of the numbers from 1 to 20?
I came up with a solution, and... |
I'm reading a data structure and algorithm book in C. I have implemented a generic single linked list in the C programming language, and I want to know your opinion on my implementation:
linked_list.h
#ifndef LINKED_LIST_H_INCLUDED
#define LINKED_LIST_H_INCLUDED
#define list_size(list) (list->size)
#define list_... |
This is a PHP database class. Yes, I know it's using the MySQL functions, which are deprecated, but I shall be updating it to MySQLi soon. Can you please review this code and give any comment on any improvements or changes you think I should make?
<?php
namespace Revolution;
if(!defined('IN_INDEX')) { die('Sorry, you... |
I inherited a script at work the other day. I know very little about the command line in general but I'm not entirely new to programming. I am using this as an opportunity to learn... Very little of the original code is left (so if it's all wrong, it's my fault now). I was asked to modify it retain sub-directories ... |
This changes the IP of msloop using WMI(Win32_NetworkAdapterConfiguration), which takes about 1~2sec.
But, if I work on another computer, it works much much slower, for about 50~60sec.
My Computer:
OS: Window 7 Professional
RAM: 8GB
Another Computer:
OS: Window XP SP3
RAM: 2GB
public void setIP () {
ManagementC... |
I wrote this out of curiosity. It is based on the theory behind Knuth's Algorithm D and is intended to emulate the behavior of the x86 div instruction (though the result is truncated instead of raising an exception for overflow).
I am primarily interested in correctness (it seems to work correctly), and have not yet co... |
This database schema will be used in conjunction with various systems as related to an online Trading Card Game, mostly for permanent storage and statistics. Some example cases would include:
JDBC calling the DB to get information about player decks, or returning after-game stats;
Website displaying stats relating to ... |
Team 7 faces a horrible foe. He can only be defeated with a special
quadruple combination attack of strength (\$1 <=S <= 10^9\$). Naruto,
Sasuke, Sakura and Kakashi must attack simultaneously to perform the
combo. Each of them can choose from \$N\$ (\$1 <= N <=1000\$) attacks,
having strengths \$si\$ each (\$0... |
I'm writing a basic search engine for my website.
It works but I'm really unhappy with the code. I know it can't be improved but I'm lacking some experiences here.
In my params from my search I get:
{"utf8"=>"✓", "authenticity_token"=>"aNY2ZVpeyZsLnIVegQPpPz/22VYx2ug+tbfu0Nzngac=", "skills"=>"3,8", "country"=>"USA", "s... |
I know it's possible for the largest factor of a number to be greater than the sqrt (e.g., for 14, 7 is the largest). Why then does almost every solution for the problem check only up to the square root? Also, I have a nagging feeling that boolean[] is not the best data structure to use here, since in this case the num... |
Here is my code which implements a simple directed graph in Java 8. Here are some of the things I am unsure about:
I am fairly new to Java 8 concepts. Have I used the new API correctly (and not increased the running time of the operations)?
In the current implementation, there is no way to iterate over the list of th... |
Part I of this question says:
Fill in the smoosh() method in the Homework3 class so that it performs as indicated in the comment. Your solution should not use linked lists, nor should it use your squish() method.
Here is the below code written for smoosh(), in more than 14 lines. Modular testing is done for this meth... |
I am absolutely confused by saveSearchHistory function. It seems dirty and unobvious.
Should I refactor it, and how?
SearchHistory.java
public class SearchHistory {
public SearchHistory(Long userId, Long groupId, String searchString) {
this.userId = userId;
this.groupId = groupId;
this.searchS... |
I am making a small library of metric data structures. That is data structures, which associate points in the n-dimensional space with objects and allow the user to find objects which are closest to a certain query with respect to a metric.
I have already implemented several data structures such as K-d trees, M-trees a... |
I use a lot of lambda expressions in C#, so I've decided to create some similar functionality in JavaScript. Since jQuery is included in my projects, I'm using $.grep() instead of Array.prototype.filter() to support older browsers without including shims.
The two examples below corresponds to Where() and FirstOrDefault... |
Part II of this question says:
Fill in the squish() method in the SList class so that it performs as indicated in the comment. Your solution should not use arrays, nor should it use your smoosh() method. Do not change the prototype of the SList constructor or the insertEnd method; our test software will call them.
Be... |
I had posted here before, but I decided that the approach used earlier - where every Vertex stores a vector of pointers to vertices it's adjacent to - was just not worth the hassle (read segfaults) it was causing me. (I'm relatively inexperienced with pointers as of now.)
Besides, a Vertex isn't more than a wrapped lon... |
I'm trying to find the greatest integer of four integers and its ties. I used the following code. Is there anyway to simplify this?
int winner = MAX(self.playerOneScore, MAX(self.playerTwoScore, MAX(self.playerThreeScore, self.playerFourScore)));
if (winner == self.playerOneScore && winner != self.playerTwoScore && ... |
SCENARIO:
As a follow-up of this question on Stackoverflow asked few days back, I am working on a swing application(article tagging tool) where the user(on an initial jpanel) would fill up some mandatory fields and then proceed to different sections(front, body and back matter of the article) where the application woul... |
Usually the socket.io's on method is like this:
socket.on('/msg', function(data){});
But in Angular that callback has to be wrapped inside its $rootScope.$apply() method otherwise anything that happens in the callback (like changing $scope properties) doesn't update in Angular.
Here's a simple way to do that:
function... |
I am developing a single user .net desktop application that lists numerous (over 2000) contacts sorted by an algorithm.
I use NHibernate and did consider a session per use case (or conversation as it is sometimes called). However, closing the session means the next time I need the contacts NH will go to the database, w... |
Can someone improve upon this function of mine? EnumToSTLContainer is supposed to make a copy of any STL container whose elements are from a specified enum list.
#include <iostream>
#include <vector>
#include <set>
enum MyEnum {A, B, C, D, E, FirstMyEnum = A, LastMyEnum = E};
template <typename CONTAINER>
CONTAINER ... |
Introduction
I'm primarily a C# programmer, just starting out with learning F#. I found myself with a problem which felt like it was appropriate for a functional language, and now that I have the first module in place, I want to get a review before ploughing on
Problem Statement
The game Bridges works as follows:
The ... |
I've read some resources on implementing NSCopying and copyWithZone, but things are still not very clear. I see many implementations with allocWithZone, which seems to be deprecated, and with autorelease, which seems to be unnecessary with ARC.
I was wondering if I can get away with something more simple. Something lik... |
I've followed a few tutorials on ARP Spoofing with Python/scapy. They all suggest activating the OS IP Forwarding in Linux:
echo 1 > /proc/sys/net/ipv4/ip_forward
This worked fine for me but has the disadvantage that I can't tamper with packets. Since I will need to demonstrate modifying a packet before sending it alo... |
The task was to find the shortest path between P and K in a maze. You can move horizontally and vertically, where # is a wall and . is free space. I've had a lot of trouble passing on the int k, which is the path length. I had to make a pair which contains a pair of x and y coordinates and int k.
Could I have done this... |
I am trying to implement Tremaux Algorithm for a 2D maze. So far the robot works well however I have some problems with retraceStep(). I'm not asking how to implement that, but I just want to make sure that there are no serious logical flaws with my code.
@Override
public boolean drive2Exit() throws Exception {
... |
I needed to write a method to extend the jQuery empty() function to include a callback. Since I didn't want to mess with namespaces, closures, etc, I instead wrote a regular function to wrap empty().
var emptyWithCallback = function(node, callback) {
console.log('Entered emptyWithCallback()');
if (typeof callba... |
I wrote my first template, but didn't include any styling. What do you think? What's good what's bad?
<?php
/*
Template Name: Email product info
*/
//checks required fields
$allFormPosts = array("address", "email", "xsize", "ysize", "zsize");
foreach($allFormPosts as $formPost){
if(isset($_POST[$formPost])){
... |
Am I doing it right? Is there some function in the standard library I should be using? This is my first real(ish) world Clojure program…
Input
(def data
[[{:id 5 :name "a"} {:id 1 :name "b"}], [{:id 4 :name "c"} {:id 1 :name "d"}]])
Code
The elements are maps and they are compared based on their :id.
(def precompute... |
I'm currently in the process of redesigning and coding my website, for which I'm wanting to use paper.js to draw on canvas. Currently the only project page I have is using a basic random ball generator on canvas with paper. I've set up a debounced resize function however the calculations seem to be taking a long time t... |
It seems like this code should be shorter, but with all the error checking it is long and hard to follow. This is for a simulation of vehicles crossing a bridge, and this part is dealing with mutexes. I tried extracting a function that is passed the mutex and locks/unlocks it and prints any errors, but when I did that ... |
Per this homework, I'm trying to implement a Fractional (Stream Integer) where the stream represents coefficients of polynomials:
where Q is defined as Q = (A'/b0) + x((1/b0)(A' − QB0)).
where A/B = Q,
That is, the first element of the result is A'/b0; the remainder is
formed by computing A' − QB' and dividing each ... |
I'm trying to write gulpfile.js, which will follow modern best practices for optimization. This project includes jekyll, SASS and some image optimization tasks. I'm pretty new to JavaScript and Gulp, so I'd love to get some feedback on this code.
You can also check the Github repo.
'use strict';
var gulp =... |
Part III of this question says:
Fill in the twin() method in the SList class so that it performs as indicated
in the comment. Your solution should not use arrays.
Below is the solution written for the twin() method in 8 lines of code. Modular testing is done for the twin() method.
public class SList {
private SL... |
The story started here (Parsing GPS Data) and continued here (Class for median filter)
I've done a lot work and faced new questions.
In short - I made:
Classes for parsers. TrackParser and inherited from it GPXParser,
TESParser, CSVParser.
Method in module ParserSelector.choose which returns object of
parser by extens... |
A project that I have been working on required data to be transferred from an Oracle database into MySQL. The process I devised for that transfer involved a query (included below) on the Oracle source database to make it dump out the schema for the relevant tables to be replicated, in the form of CREATE TABLE statemen... |
I'm developing a legend toggling d3.js pie chart application using this jsFiddle as my latest version.
I am aiming to get a streamlined working example where the legend can toggle the slices, trying to deactivate all slices - resorts in a reset which reactivates all the slices. Splitting up presentation and application... |
I wrote this script for a proof of concept JavaScript password cracker:
var charset = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
function crack(value){
function toRadix(N,radix) {
var HexN = "",
Q = Math.floor(Math.abs(N)),
R... |
I'm writing an application that needs to verify that an Active Directory user is in a certain OU or group. This allows me to tell if the user is a Field Agent or a Home Office User. However, I didn't want to fixate on one OU and one group, so I allow the OU names and group names to be comma separate values in the web.c... |
I am using AFNetworking 1.4.3 to send and receive network messages in iOS. My application works slightly differently in DEBUG and RELEASE mode, so I need to use #ifdef clauses. How can I simplify the following fragments without making these macros:
#ifdef DEBUG
if (failure) failure([NSError fromDict:responseO... |
I am trying to make a cyclic iterator that works backwards and forwards. getNext() gets the next array item, getPrevious() gets the item before the last returned one from getNext(). This seems to work, but there must be a better way. How can this be refactored?
var cyclicIterator = function (arr) {
var index = 0;
... |
I've produced the beginnings of an RPG-style game using HTML5 and canvas. So far you can use the keyboard controls WASD to move an avatar around a simple tile-based map. The map is constructed of individual 'room' maps which form a larger 'world' map. The use of a 'world' map allows the avatar to walk off the screen an... |
I created a Windows Service that Tracks which App Server a user is actually connected to through a load balancer.
It retrieves the user that is logged into windows on that machine, then cross references the Active Directory (AD) account to return the first name, last name and E-mail (for notification through the websi... |
Is this code well protected, and if not, could you tell me how it might be exploited and how to secure it?
if(isset($_POST['vrsta_predmeta']) AND !empty($_POST['vrsta_predmeta']) AND
isset($_POST['res_text']) AND isset($_POST['glavni_dug']) AND isset($_POST['res']) AND isset($_POST['zaklj']) AND isset($_POST['povjeri... |
This question is inspired by:
Generic Task Scheduler
where the problem is to run tasks on a scheduled basis, in parallel, and have individual timeouts for each job.
For example, consider this use-case:
BatchedJobHandler.TaskSupplier<Long, SleepTask> supplier =
() -> getTasksForExecution();
BatchedJobHand... |
I'm wonder if my approach is correct. I'm trying to make a WinForms server that processes data from 3 sides:
from bluettoh (InTheHand library) as source data which I need to process in server
to local network (TcpListener/TcpClient) to send processed result from Bluetooth data
from local network (TcpListener/TcpClient... |
I wrote simple search engine based on TF-IDF statistic and cosine similarity. I am still learning Scala, so would be glad to hear comments (here or at GitHub) regarding my code from Scala professionals.
package search
package object types {
type Word = String
type DocumentTitle = String
type SearchResult = (Docu... |
I need to convert some CSV data into a format recognizable by some old script my work uses. Changing the format is pretty much out of the question. So I've written this:
$rate_plan_terms = [
"pp",
"01",
"12",
"24",
"36"
]
def generate(fname)
puts "generating doc for #{fname}"
file = File.open(fname)
st... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.