instruction stringlengths 71 71.9k |
|---|
I wrote the following snippet to deal with a situation in which I have two datasets (usually the current version versus a previous one) and I need to identify what changes have occured: usually explaining the deltas of one specific column.
I want to identify what rows have been added, what rows have been removed as wel... |
For practicing purposes, I challenged myself to write a program that solves the TSP and visualises the results step by step.
As for now, my program uses a simple nearest neighbour algorithm. I want my program to be flexible, so when I add a new algorithm, it will be able to visualise the results, too, without messing w... |
The Problem
Given a list of dependencies ('a * 'a) list where the first item has a dependency on the second item, construct a dependency graph and then 'flatten' it into a single 'a list such that no item comes after one of its dependencies.
Constraints
I am trying to improve my functional programming/idiomatic F#, so ... |
I have this code that creates (or updates) a user from an omniauth hash parameter:
def self.find_or_create_from_auth_hash(auth_hash)
uid = auth_hash['uid']
provider = auth_hash['provider']
user = find_or_create_by(uid: uid, provider: provider)
user.name = auth_hash['info']['name'] || ''
user.ema... |
Inspired by Minimising the triangle
I am writing a fully tested program to solve the following problem:
A triangle needs a good foundation. Every row in the triangle is derived from the sum of the two values below it. However, there can be
no repeated values, if a value shows up more than once the triangle
crumbl... |
I've written a little program to calculate pi using the Nilakantha series:
For this formula, take three and start alternating between adding and subtracting fractions with numerators of 4 and denominators that are the product of three consecutive integers which increase with every new iteration. Each subsequent fracti... |
The expected functionality is that a user/vehicle interacts with a ParkingLot and it allots the space in Park method based on type of vehicle (here I can expect a few changes, like increase from regular and handicapped to one more functionality for celebrities etc). What would be the route to perfect object oriented co... |
A few years ago I modified version 1.8.1 of Jason Blevins's markdown-mode for Emacs so that when showing inline links the URL is hidden, and so that you can follow the link simply by hitting Enter. If you want to see the URL you can still see it by, say, removing the final ). It's based on linkd, though I'm told that o... |
The prompt that made me put this function together was sourced from CodingBat.
I was curious about cleaner, more correct methods of doing putting this together such as finding a cleaner way to tell if there is or is not a duplicate in the array. I am also trying to be as efficient as possible. I believe this is an \$O(... |
I have just installed Ubuntu and am re-familiarizing myself with Python. I learned the basics in late 2012-early 2013 and I'm practicing with it in order to get better at programming concepts and practice.
'''
Snake Game
implements gameplay of classic snake
game with Tkinter
Author: Tracy Lynn Wesley
'''
import threa... |
Is it possible to declare multiple arrays in PHP in one line?
$userAnswers = array();
$questionIDs = array ();
$sqlAnswers = array();
$sqlAnswersQuery = array();
$correctAnswers = array();
Any cleaner ways of doing this?
NOTE: The contents of these arrays are all DIFFERENT. I don't think setting them equal to each ot... |
My colleagues often ask me, "Dude could you remind me what I have to type to build this target?". So I eventually implemented a nice workaround in my Makefiles.
I wanted my Makefiles to have a help target that give some usage clues to the users. This is achieved with an embedded Perl script and some markers.
Wherever ... |
The following snippet will return a list containing the words in all of the works of Shakespeare:
>>>def shakespeare_tokens(path = 'shakespeare.txt', url = 'http://inst.eecs.berkeley.edu/~cs61a/fa11/shakespeare.txt'):
"""Return the words of Shakespeare's plays as a list"""
import os
from urllib.... |
I have this one single line of code I wanted to improve. My main concern is the execution and rendering speed of it. Even though I am happy with its speed, could it be improved?
document.getElementById('my-webpart').style.height =
(document.documentElement.clientHeight - 80) + 'px';
The reason I didn't ad any variabl... |
While writing a review of @MotokoKusanagi's Brainfuck interpreter, I decided to write my own implementation to illustrate a few points. In particular, I'd like it to be robust to malformed programs, and reasonably efficient (short of JITting the Brainfuck code).
Please point out any deficiencies you might find in this... |
My previous post had no response, so there is part of the whole - levels service. It stores levels with it's attributes. I'd like to hear any suggestions about code readability and code performance.
(function() {
'use strict';
angular
.module('app.mine')
.service('levels', LevelsService);
... |
I load a table in a div using the .load() method. If I look on the console I see the times taken to display the table:
4.98 seconds that firebugs says are spent "waiting" for a response (from a PHP backend)
9.94 seconds receiving data.
During the second event I see that the browser throws an alert saying that the scr... |
I have created an app in which URLs stored in a database are pinged via curl to check their availability and the database is updated with the results.
Two tables are updated with each fresh ping of a website (Site -- the status recieved 200, 404 etc) and (History - time of each ping, time taken, result etc) From my und... |
I have started putting together a functional programming library in C# which is somewhat inspired by scalaz and the book Functional Programming in Scala.
I am hoping to get some feedback on the Monad Transformers implementations and comments.
Please understand this is implemented in C# and .NET, which does not support ... |
I have a "generic" cache object:
public class Cache {
private static final Map<Class, ICacheable> cacheMap = new HashMap<>();
public static ICacheable getCacheableElement(Class cacheableElementClass, Object... params) {
ICacheable cacheableElement = cacheMap.get(cacheableElementClass);
if (cac... |
I have a lot of filter classes which are named after the method names they filter by.
For example:
OrderByBestValueFilter corresponds to #best_value
OrderByPriceFilter corresponds to #price
and so on...
Since I'm doing a lot of these transformations, and the point of this set us is to make filters easy to add or ... |
I'm very new to SQL, but I'm coding a C# program that interacts with a database. There's a master database on my computer, and there's a client database on my tablet.
When I re-connect my tablet to the network, I want it to merge the two databases, so that changes made on the tablet are pushed to the master, and chang... |
#include<iostream>
#include<string>
using namespace std;
int main()
{
string s, sub;
cin >> s;
int check = 1, count = 0, pos = 0; // keeping count of number of alphabetical ordered substring characters
int i = 1; // loop variable
int prev = 0; //to hold previous value of loop variable
while (... |
I know there must be a better way to perform the above sub than using multiple If statements. I was thinking of storing the obj.PropertName into a collection and run it through a for loop.
'Create instance
Dim wellObj As CWell
Set wellObj = New CWell
.
.
.
Private Sub Well_List_Click()
'Must check if null..
I... |
I've found that the function genfromtxt from numpy in Python is very slow.
Therefore I decided to wrap a subroutine with f2py to read my data. The data is a matrix.
subroutine genfromtxt(filename, nx, ny, a)
implicit none
character(100):: filename
real, dimension(ny,nx) :: a
integer :: row, col, ny, nx
... |
I think the inherent relations in this query should be self-evident:
ShipmentStatus.joins(shipment: :shipment_users)
.where("shipment_users.user_id = ?", user.id)
I have a feeling there's maybe a shorter way to express this. Can it be reduced?
|
I put this together and am having some doubts to the number of connections I can make. I also doubt if I can brute force the server to serve up connections and then hang.
Please take a look and tell me what I can do better.
'''
Simple socket server using threads
'''
import socket
import sys
from thread import *
... |
Basically, I want to write a huge file of numbers. Each line in that file should contain one number. This program below is extremely slow (obviously) but it works. It writes one line after line and always one number until the limit of an unsigned long has been reached.
#include <iostream>
#include <limits>
#include <fs... |
Is the trade-off between simplicity and performance worth it?
def is_sorted(list_):
"""
Is the list sorted?
The simpler `list_ == list(sorted(list_))` has
time complexity O(N log N), this O(n).
>>> is_sorted([1, 2, 3])
True
>>> is_sorted([1, 2, 7, 3])
False
"""
return all(curr ... |
The problem is that I'm checking if result from cursor exists in CDN.ZamNag table for every iteration. Is there any better way to check if values in table 1 are also in table 2?
Time of executing below procedure takes 1 minute and 30 seconds - I'm searching for any ideas which will make executing shorter.
IF (SELECT ob... |
See the previous iteration. See the next iteration.
I emphasized the fact that serialization routine may not return a string with new line character by using more or less explicit identifier. Moved the actual de/serialization routines to a factory class. That's what I have:
LineStringSerializationFactory.java:
package ... |
I have black Raw Bayer Images RGGB color space. I want to go over each pixel in their channel and sum them up for each channel, then divide it by the number of pixels for each channel. I'm trying to build a fast optimized algorithm.
Here is how I have started. The code runs but I still have some issues with the results... |
I wrote a series of questions in a previous post, and a user recommended that I separate the questions.
I have made the switch from procedural programming to object-oriented programming. I have grasped/utilized the benefits of OOP, but I am still struggling with the placement of the business logic for the application.
... |
As the name says, LongModulus is a pretty long (lengthy) class implementing modular arithmetic for a long modulus. As overflow is a problem, I implemented two subclasses, one for moduli not using the highest non-sign bit (i.e., smaller than \$2^{62}\$) and one for the others.
The code uses Guava and Lombok. As usual, f... |
I'm working on The Python Challenge. The current code iterates over a 98,766-character string before printing an 8-character string. Current execution time is between 7 and 10 seconds.
How can I optimize my current code and what rookie mistakes am I making that may be adding to the execution time?
import urllib.request... |
This code counts down from 30 to -999 on a 7-segment 4-digit display; it works but I don't know if it is a good way to do it or if it follows best practices. I want to start writing libraries for components that are not specifically made for Arduino. This is my first attempt. Please tell me if there are any problems... |
I need to parse the data coming from the URL which looks like this:
hasProcess=true
version=1
DATACENTER=abc
TotalNumberOfServers:4
primary:{0=1, 1=2, 2=1, 3=2, 4=1, 5=2, 6=1, 7=2, 8=1, 9=2, 10=1, 11=2, 12=1, 13=2}
secondary:{0=0, 1=0, 2=0, 3=1, 4=0, 5=0, 6=0, 7=1, 8=0, 9=0, 10=0, 11=1, 12=0, 13=0}
host... |
This is a simple piece of code which takes two arrays supplied as parameters, then appends them to a new array that contains the values from the supplied arrays. Any suggestions for improvement would be greatly appreciated.
public static int[] append(int[] list1, int[] list2) {
int[] appendedList = new int[list1... |
I'm working in a game as a hobbie. I'm using an Entity/Component/System architecture using Libgdx as Engine and Ashley as Entity Framework.
I have a GamePlayScreen in which I initialize my system, creating Entities, Systems and Components. Below is a tiny code snippet of class constructor with the calls to severals 'c... |
To aid in the localization of .resx files, I made a generic resx comparer that allows you to edit the values of the resx's. Also, this is my first proper adventure in WPF (I've just been using Windows-runtime before).
This is my view interface:
public interface IResxTranslationHelperWindow
{
object DataContext { ... |
I asked this question and I have made enough changes, so I think it deserves a new question.
The Problem:
A triangle needs a good foundation. Every row in the triangle is derived from the sum of the two values below it. However, there can be no repeated values, if a value shows up more than once the triangle crumbles.... |
I am exploring different ways of implementing a linked list in Rust as a learning project. In one particular place, I've got some code that works properly, but it makes multiple calls to unwrap--I am under the impression this is generally regarded as unsafe/poor style. I'd like to make it better.
Here are some releva... |
I have implemented the K-Nearest Neighbor algorithm with Euclidean distance in R. It works fine but takes tremendously huge time than the library function (get.knn). Please point out the possibility of improvement.
knn<-function(list,k){
n=nrow(list)
if (n<=k) stop("k can not be more than n-1")
neigh<- matrix(0,n... |
My first use of classes with Python. Very simple code which I feel may be further simplified. Please break my code or give me input on where it could have been better/efficient.
import maya.cmds as mc
from functools import partial
class MoveSelTool(object):
'''Tool for moving selected object or objects by a
v... |
The code below is pretty self explanatory: just copy and paste it all into a module and run it, it provides a few use cases and many explanatory comments in the text. (It works but I'm interested to know what other people make of it and for any suggestions you might like to make.)
The most important facts to realise ar... |
The file I'm processing here is an outputted file from a Java library called duke.
Its goal was go through all purchases made on a site and group them into a single customer. The output is a csv file in the format, you'll find an example of it below the code.
I want to know if I've written this in a readable way or if... |
I was assigned a task to make a simple jar that can handle 2 console commands -> create key value, read key. I have 4 classes, where my main logic is implemented. Eg. create bulgaria sofia, creates a record in a serialized file with a key - bulgaria and value - sofia. Any feedback about the code and the idea are more t... |
I wrote a code in Python to solve Knapsack problem using branch and bound. I tested it with the case from Rosetta and it outputs correctly. But this is my first time to write this kind of code, I am feeling unconfident. Could you please review my code and give me some tips to improve it?
A tourist wants to make a good... |
I have very little experience with C, so I decided to code a simple numerical program.
An Armstrong number with \$N\$ digits is a number that is equal to the sum of its digits to the \$N^{th}\$ power, in pseudo-code:
sum { power(digit, N) for digit in number } == number
My program finds all the Armstrong numbers below... |
I wrote some C++ code using the OpenCV library. The program reads the image and plot histograms of Red, Green, and Blue components. I am very new to OpenCV so I need comments and advice. What do you think about my code? Is there any better way to do that? Are there unnecessary parts in my code? Is there any part I shou... |
I need to round numeric values for properties of a given object.
The following code works fine, but I am concerned if there is a way to make it faster.
I am targeting latest Chrome and Firefox.
http://jsbin.com/bahedegoni/edit?html,output
window.app = {
start: function () {
var cmd = {
... |
Having read most of Learn You a Haskell as well as parts of Real World Haskell, I decided to embark on an easy project to see if I can apply the Haskell that I've learned.
{-# LANGUAGE OverloadedStrings #-}
import Data.Maybe
import Text.Regex.TDFA
import qualified Data.ByteString.Char8 as B
main = do
dictionar... |
My program uses the Knuth–Morris–Pratt algorithm to search for a particular substring in a .txt file and then store it in a binary search tree.
Note that testfile.txt should be contain only spaces and normal characters (no newlines! - except maybe as the last byte).
There is a lot of code, so note that I am primarily c... |
When you own an Android device and want your iTunes playlist to be copied over onto it, what do you do?
What if your playlist hits something in the region of 20GB+ ? Well, I am sure I could've paid for a tool, to do this for me and keep things in sync, but I wanted to challenge myself into writing something in Python t... |
After reading this, I'm on board, however it doesn't get into passing methods from the parent class. In my mixins right now I have a lot of helper functions that are used across the various components that use the mixin.
I would simply do something like below, unless someone has a better approach? Note I have anywhere ... |
I was given a tech test for a prospective job a small game that uses Facebook API to connect a user then to guess the image. The feedback from the employer was good but they said they had to modify part of my code to get the API connection working even though the demo app works fine. This has caused them to lower the o... |
I'm trying to have the 3 buttons to each open its own list below whilst closing any current active lists open. I've tried my best with jQuery, but it seems so bloated. Is there a way to streamline this?
At the moment I have a very rough working example:
/***********************
Mobile Menus
************************... |
I wanted to center some text in my commandline application, so I came up with this function.
centerText(){
textsize=${#1}
spacecount=$(tput cols)
spacecount=$((($spacecount-$textsize)/2))
while [ $spacecount -gt 0 ]
do
printf " "
spacecount=$((spacecount-1))
done
printf "$1"
echo
}
If you have suggesti... |
I'm trying to have the 3 buttons to each open its own list below whilst closing any current active lists open. I've tried my best with the jQuery, but it seems so bloated. Is there a way to streamline this jQuery code?
At the moment I have a very rough working example.
/***********************
Mobile Menus
***********... |
I'm making a really simple html website with CSS and I was hoping on some feedback. A few notes:
There will be more content under this, but I want the starting screen to take up the full page and then scroll under it.
I've used a bit of a hack to remove the padding from the first list element
I've used a bit of a hac... |
I'm just at the beginning stages of making a simple chess engine. I have a function that when passed the x and y coordinates on a 2D list can enumerate all possible moves for a piece. It assumes there are no other pieces on the board, and that all moves are possible (see example list of moves below) and a separate func... |
This code validates the following:
enddate should not be less than or equal to startdate.
startdate should not be less than or equal to the date today unless document.getElementById("ltype").value == "1".
The maximum gap between startdate and enddate is one year, more than that should cause an error alert.
Please rev... |
My goal is to remove whitespaces from string elements of my list, and to remove empty string elements altogether. My code:
def modifylist(lst):
lst = [elt.strip() if type(elt) is str else elt for elt in lst]
while '' in lst:
lst.remove('')
return lst
Is there any other method th... |
I have the following code:
for j in range(rows):
for i in range(cols):
k = j * rows + i
k1 = k + 1 if i < cols - 1 else k - 1
k2 = k - 1 if i > 0 else k + 1
k3 = k + cols if j < rows - 1 else k - cols
k4 = k - cols if j > 0 else k + cols
w1 = U[k]
w2 = U[k-... |
A tourist wants to make a good trip at the weekend with his friends. They will go to the mountains to see the wonders of nature, so he needs to pack well for the trip. He has a good knapsack for carrying things, but knows that he can carry a maximum of only 4kg in it and it will have to last the whole day. He creates ... |
I am writing a solved for 15 puzzle game which will find the solution path to any NxN board. For easier boards the algorithm works great solving almost any 3x3 boards, most 4x4 boards, but when I go 5x5 and higher I will often run out of memory. This is the implementation:
@WorkerThread
public Solution findPath(Board b... |
I was solving this question on a site that gives you a 1d array called grid
grid = ['top left', 'top middle', 'top right',
'middle left', 'center', 'middle right',
'bottom left', 'bottom middle', 'bottom right']
and you're expected to write a method fire(x,y) that takes in two coordinates ... |
I've seen a lot of Brainf**k interpreters in various languages. I decided that actually interpreting Brainf**k is too hard, so instead of that, I wrote a 'compiler' in Ruby that directly transcribes BF to Ruby code. This is Version 1.0, and I'm looking for any tips on how to make it more efficient.
There are a few thin... |
I'm sending data from a form with a variable number of fields via an Ajax call. Some of the fields are grouped together so I have opted to send them as an array of JSON objects to keep the groupings, but there are a number of ways of doing this. For client-side, is it better to read the form as JavaScript objects and ... |
The algorithm works in steps:
Produce the graph in the form of an adjacency list
e.g. this graph
0 - - 2
\
1 -- 3
produces this adjacency list
{0: [], 1: [0], 2: [0], 3: [1, 2]}
0 depends on nothing, 1 depends on 0 etc..
Iterate through the graph and find nodes that does not have any dependencies
Question... |
I'm in the process of refactoring one of my open source projects, branch here.
The basic idea of the refactor is to allow for classes and all of its children in the graph to be scoped. I wrote a blog post about it here.
The container is abstracted into an interface:
public interface IScopedContext : IDisposable
{
}
... |
This code feels long and clunky to me. How can I make it shorter, if possible?
I am writing for a libGDX game, and I need a skill algorithm.
I want it so once the player picks up something (which I already have checked for) I set a, b or c to a certain SkillType, the enum down below. Then, I want to get the value of th... |
Based on a question on SO I thought I'd knock up a cmdlet to perform an unpivot on an object. I've not yet considered all the options (e.g. what happens when objects with empty lists are passed), so there are likely a few issues, but I wanted to get it out to the community early / see if people think this is useful or... |
I would like to get opinion if I am doing this right. I am creating a helper class that is globally accessible to my whole project. I want it to be easily called like Facebook.loginUser()
My code is like this:
class Facebook: NSObject {
class func LoginUser() {
println("Login user...")
}
}
And on usage just c... |
I wrote a function to reduce the size of JSON objects that works simply by turning every associative array into an indexed one, and moving each property's name to the first row of the data array (ordering it a bit like a CSV file, I guess).
<?php
/**
* Converts a list of associative arrays into indexed arrays.
*
* ... |
Can you please tell me whether this is a good way to get the user's IP (IPv4 or IPv6)? Does someone have a better way to do this? Please take a look at the entire code, the server_params order and the comments.
/* We are looking for ip in server params */
$server_params = array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR',... |
Previous iteration.
You know, I think this is the fastest I've ever pushed out an update to anything. This is Version 2 of my Brainf**k to Ruby converter, and the generated code looks... Well, like Brainf**k, converted directly to Ruby, with no attempt at making it more readable.
I'm looking for any tips on making thin... |
In context of preparing for a coding interview, I gave the division problem a go using Java. This is what I came up with. It's a little bit different to other solutions I've come across the interweb.
Implement integer division without using multiplication or repeated subtraction (i.e. to divide n by d, you man not rep... |
I am looking to implement a method that is capable of merging 2 dictionaries using generics. I've seen several great answers on SO already, but none handle the case of nested dictionaries. As in, what if the value of the dictionaries is another dictionary.
In order to tackle this, I created the following method:
using ... |
I have a login web page where a user enters their email and password and I need to check if:
the entered email exists in the DB and
the entered password matches the hashed one from the db.
The password in the DB was hashed with
$pw = password_hash($_POST["pw"], PASSWORD_BCRYPT);
and is stored in a VARCHAR(255) colum... |
See the previous iteration. I have incorporated the answer of h.j.k.. Now I have:
LineStringSerializationFactory.java:
package net.coderodde.lists.serial;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Scanner;
/**
* This class contains static methods for serializing... |
I've written a method for an API call that updates a store menu. It takes JSON as input, in the following format:
{
"menu" : {
"item_groups" : [
{
"id" : 1,
"name" : "Drinks",
"items" : [
{
"id" : 1,
... |
A little background - these are classes I've written on top of an Entity Framework model that represents tables on Sql Server with the following names:
Dictionary.Databases, Dictionary.Schemas, Dictionary.Tables, Dictionary.Columns
SysData.Databases, SysData.Schemas, SysData.Tables, SysData.Columns
Compare.Databases,... |
I wrote the following simple function in JavaScript that finds the sum of all the multiples of 3 or 5 below a value, given from a text-box.
I have used \$\dfrac{n}{2(a_1 + a_n)}\$ (sum of arithmetic sequence).
I was wondering if there is a way to shorten or otherwise improve this code.
function sum_of_all_mul_3_5(){
... |
Since it has too many loop, loop inside loop, this works very slowly. How can we increase the speed of this program? I am trying to copy a range from one file to another file of same name in different folder. I have folders named "A","B","C"..."G" inside c:\Charts\1\ and c:\Charts\0\. Inside each folder "A","B","C"..."... |
I am trying to optimize the usage of TopicClients in my app. The instance is originally covered by interface and passed by IoC, so the IoC will dispose it at the end of the program life cycle. This way I think I am saving some resources for the create/dispose of the client.Is such an implementation safe? Are there any ... |
First version: Go (board game) in Java
What's new:
I now use (as advised) HashMap<GoPoint, StoneColor> where GoPoint is my "coordinate" class and StoneColor is an enum.
Game allows only legal moves.
Player can pass (skip turn).
Player can choose the size of game board.
Code is more readable (I hope).
Better separatio... |
The following code creates a JFrame with a JTextField array in it. It also creates a JMenuBar at the top which allows you to select how many JTextFields you want to display (1-20) and then uses various layouts to display them on the JPanel.
I'm looking mainly for comments/thoughts on how the program lays out the JTextF... |
My service:
myApp.factory("MediaService", ['$http',
function($http) {
return {
all: function() {
return $http.get('/media');
},
save: function( data ) {
return $http.post('/media', data);
}
}
}
]);
My controller:
myApp.controller("MediaController", ['$h... |
I've created a decorator in my Rails application. However, the initializer has 3 params. Is this generally acceptable in decorator or should I refactor this or try a different pattern?
class FileBinderDecorator
attr_reader :binder, :credential, :page
def initialize(binder, credential, page = 1)
@binder = binde... |
I have the following 4 functions that work, however, I am sure that utilising promises will improve my code. I just find them so confusing.
$scope.takePictures = function() {
document.addEventListener("deviceready", function() {
var options = {
quality: 75,
destinationType: Camera.... |
I am working on writing a Code Golf King of the Hill challenge, the details of which can be read here. You can read the full code here.
Briefly, the game proceeds in cycles of night then day. There are two mafia, who collectively kill one person at night, and five town sided players (some of whom have roles during the ... |
I have an ArrayList of Strings. I want to delete all elements with a particular value and the element immediately after that one.
I have an ArrayList with the elements "Ape", "Bear", "Cat", "Dog", "Emu", "Fox", and "Gopher". Any time I see "Cat", I want to delete "Cat" and the element immediately following it. So in... |
This code calculates the factorial of a number on multiple threads. My issue: it is only a little bit faster than the sequential version of it (and I think I know why, I just can't find a way to solve this).
I use boost::multiprecision::cpp_int so the limits of default integers are not a problem, the size of integers i... |
I have a Ruby program which should solve the following problem:
Consider the divisors of 30: 1,2,3,5,6,10,15,30. It can be seen that
for every divisor d of 30, d+30/d is prime.
Find the sum of all positive integers n not exceeding 100 000 000 such
that for every divisor d of n, d+n/d is prime.
require 'prime'
cl... |
I am new to Perl and I wrote this Perl script to calculate bytes of code and lines of code in a directory. I want to know if there are any improvements that can be made to it.
#!/usr/bin/perl
# codestats.pl
# A perl script to calculate the number of lines of code in a project
# and what type of lines those code are, su... |
In my system I have a history repository.
My history class is big and with a lot of information regarding operations.
My warehouse needs, for some actions to know which histories are caused by the same action.
My first idea was to create an overloaded version of each method requiring to write histories and make all the... |
This is working code from a dataTable, which shows the function executed after the row is created:
"createdRow" : function (nRow, data, iDataIndex) {
var $row = $(datatable.row(nRow).draw().node());
var $quantityInput= $row.find("input.quantity");
var rowClass;
if ... |
Here is a code snippet of a class that I be interested to refactor. I was in doubt on how to proceed with the process of instantiation. The original ask was here. After think about it and heard some opinions I end up refactoring and splitting the instantiation in several constructors, one public and all others private.... |
I have written this script that downloads two tables from the db, preforms an intersection on them and adds 2 new columns to the resulting table, and uploads the resulting table to the db. It's a bit slow and I realize my code is messy (I'm new to Python and GIS). I suspect more steps can be done in parallel, for examp... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.