instruction stringlengths 71 39k |
|---|
Just wanted a way of attaching a jQuery search plugin to an input element (or collection) and be able to pass specific options at invoke time:
This is the plugin code
(function($){
$.fn.extend({
enableSearch:function(opts,callback){
return this
.bind('focus',function(){
$(this.form.elements).val(''); ... |
I'm aware standard delegate method declaration should include the object that triggers the method, usually of the class that declared the protocol.
That's fine when the delegate method includes further arguments down the line, but what if it doesn't?
Example:
@protocol MyObjectDelegate <NSObject>
- (void)myObject:(id)... |
I have two types of session wrappers:
Type 1
public class SessionHandler
{
public static SessionHandler CurrentSession
{
get
{
SessionHandler session =
(SessionHandler)HttpContext.Current.Session["SessionId"];
if (session == null)
{
... |
This my first Python program and game. Can you please point how I can improve and what code should be changed?
import pygame
from pygame import *
import random
import time
import os
import sys
from pygame.locals import *
black = (0,0,0)
white = (255,255,255)
pygame.init()
def game():
os.environ['SDL_VIDEO_CENTERE... |
I recently wrote a snippet to make a custom array.indexOf but with nested array support in addition to allow using a nested array as needle.
For example, it correctly returns the index 3 in this case:
var arr1=[0,1,2,[3,[4,true,[],[,"x",false,,,undefined,[]]],["5"]]];
console.log(indexOfArr(arr1,[3,[4,true,[],[,"x",fal... |
I create a simple feature tour sort of like what rdio and Facebook are doing. How can I make it better?
$(function () {
$('a.close, a.closebtn').click(function () {
$(".tour-block").hide();
});
$('a.tour-step-01').click(function () {
$(".tour-block").hide();
$(".tour-block.tr01").fa... |
Shape represents an abstract class and the other two classes inherits from it. This looks insufficiently abstract to me. How could I improve it?
import math
class Point:
def __init__(self,x,y):
self.x = x
self.y = y
def move(self,x,y):
self.x += x
self.y += y
def __str__(s... |
I occasionally find myself bumping into code like this (either in other projects or banging out initial prototypes myself):
if @product.save
if current_member.role == "admin"
redirect_to krowd_path(@product)
else
redirect_to new_product_offer_path(@product)
end
else
render :new
end
Wha... |
This is the "Codebreaker" game in Ruby. Tell me what I can make better!
#!/usr/bin/env ruby
class Sequence
attr_accessor :guess, :code
def initialize
puts "Type the difficulty level you would like: 1, 2, 3, 4, or 5"
begin
@level = gets; @level = @level.to_i
if @level > 6
raise "Error"
... |
So I spent a while this morning creating an xml parser in java which is part of a job interview. I would love to have some people tear it apart so I can learn from any mistakes that I made so I can grow for future job interviews.
XML file:
<Employees>
<Employee>
<Name> First Last</Name>
<ID> 00001 ... |
I have this Facebook class and I'm wondering if the OOP nature of it could be improved at all?
(GitHub project here):
<?php
class Facebook {
private $baseUrl = 'https://graph.facebook.com/';
public function basicInfo($username){
if($username !== ''){
$url = $this->baseUrl . $username;
}... |
What is the best way to optimize this jQuery code?
$('#hde_test').hide();
$('#shw_test').click(function() {
$('#shw_test').hide();
$('#hde_test').show();
$('.class1').show();
});
$('#hde_test').click(function() {
$('#shw_test').show();
$('#hde_test').hide();
$('.class1').hide();
});
|
I have created a queue in javascript. This queue also has blocking take(). As you all probably know this is not really true, because javascript does not have threads. It just wait until element has been added to queue. You can view to source-code at https://gist.github.com/2467432. I try to write testable code. As you ... |
Starting from a specific number of 1-element sets, I want to pair these sets together (forming 2-elements sets), then pair the paired sets with the original one-element sets (forming 3-elements sets), etc...
For example, if I start with these 1-element sets:
{1}, {2}, {3}, {4}
After pairing them together I will get:
{... |
This is my code that implements Dijkstra's single source shortest path algorithm, which is called multiple times to recalculate after graph changes. the graph is a road system of a city and shortest path needs to be calculated when certain roads close one at a time.
I am looking for advice on the following:
Will this ... |
I have been working on a personal CMS for a site I've been running, and right now I'm working on a page that lists all entries, or posts from a database. I have given the user, with checkboxes and a drop down menu, the option to either delete or edit a post.
//query database
$query = mysql_query("SELECT * FROM ... |
I need to remove last text after : in my String and : too. I have tried this. Please review. If there is a better way to do, please tell me.
String test = "temp:content:region:deposit:up";
System.out.println(test.replace(test.substring(test.lastIndexOf(":"), test.length()), ""));
|
I try to learn amd64 assembler. This is the first thing I tried. This piece of assembly should replicate the functionality of the following piece of C code, which turns a binary sha-256 hash into a human readable form.
assembly code
1: .ascii "0123456789abcdef"
.global show_hash
show_hash:
.type show_hash @fun... |
Is there a way to reduce this lengthy if condition:
if(
statusCode.equals( NO_ERRORS_NO_WARNINGS ) ||
statusCode.equals( HAS_ERRORS_NO_WARNINGS ) ||
statusCode.equals( HAS_ERRORS_HAS_WARNINGS ) ||
statusCode.equals( NO_ERRORS_HAS_WARNINGS )
){
//do something
}
The purpose of it is to see if there ... |
I'm facing an interesting issue at the moment:
My Situation:
I'm having (in Java) String-Arrays like the following (more complicated, of course). Each String-Array represents one sentence (I cant change the representation):
String[] tokens = {"This", "is", "just", "an", "example", "."};
My Problem:
I want to rebui... |
I am implementing RSA algorithm in C++ and here's my design(code structure).
keygen.h
namespace rsa{
class keygen{
public:
//Constructor
keygen(size);
//Generate keys
void generate();
//Getters
char* gete(){ return xyz; }
..
..
..
... |
I have a method that exacts data from an XML and returns an IEnumerable<Foo>. I am trying to create a method that will merge the results from 2 different XML's files into a single IEnumerable and remove any duplicate data that may be found
A duplicate in this case is defined as 2 Foo objects that have the same Name p... |
Ive written a script to loop through a couple of unparalleled arrays a loop within a loop, Now im trying to find out if using break is all that's needed to exit and then continue over again.
What eles can you see or know to improve this?
var arr_vals = ["74","f4e3","22","r31","17","hundernds"]; // could have 500+ items... |
I'm working on a show/hide div with checkbox on change and on load. I've come up with this so far:
jsFiddle
$(document).ready(function() {
var $cbtextbook = $('#in-product_category-14'),
$cbimod = $('#in-product_category-15'),
$mb1 = $('#mbtextbook'),
$mb2 = $('#mbimod');
function tbmb() {
if ($cbtex... |
Carrying on from:
Yet another C++ Json Parser
Yet another C++ Json Parser (Recursive)
All the code is available from git hub: ThorsSerializer but only reviewing a small section here.
The idea is that using this library it should be easy to define how a class is serialized without writing any code. See example in READ... |
I have a basic class that I'd like to get some feedback on. I'm refactoring some old code but the new code looks more complex. Basically I'm passing a list of included and excluded cultures into a function that should return if the current culture should be allowed. Exclusions win. Any advice how to better it would b... |
Is this correct coding for prepared statements in php. I've done some reading but the best way to learn is criticism from peers. Any suggestions to improve this code? Anything I've done wrong? Thanks you!
$dbh = new PDO('mysql:host=localhost;dbname=tests;charset=UTF-8', $user, $pass);
$stmt = $dbh->prepare('INSERT... |
I am using an external library named enchant here. My problem is that I guess my program is not returning all possible English words and is slow as well for large string input.
I am using both en_US and en_UK here:
import enchant
import itertools
uk = enchant.Dict("en_UK")
us=enchant.Dict("en_US")
a=[] # stores all pos... |
We implement a C++ class Proposition that represents a (possibly compound) propositional logic statement made up of named atomic variables combined with the operators AND, OR, NOT, IMPLIES and IFF.
We then use it to find all the truth assignments of the following proposition:
((A and not B) implies C) and ((not A) iff... |
I have written a helper method which computes the sum of values in some custom grid, given the column indexes. The method appears to work (for a decimal - as Anthony pointed out, I need to test this further), but I am not at ease with the following conversions:
decimal valIfNull = (decimal)(object)valueIfNull;
return (... |
I come from a Java background so my desire for proper unambiguous logging is strong. I prefer using the console to using some other gui widget however, in the browser I know that I can't always count on the console to exist or for it to have all the levels I might like. To remedy this I worked up the following console ... |
I've been working some forth looking on design patterns, and I would like some help to improve the code (fixes, tips, just generally improvements, or things you consider bad practise, etcetera in my code).
And finally: Am I on the right track, or should just back the wheel and start over?
UserMapper
<?php
class UserM... |
The following code is part a class called class db_tables. All the other getTbl* methods other than getTblHerd pull information based on the ID of the animal that is passed to them.
My question is while the following code works would it be better to move all the other getTbl methods into the Animal class and pass them ... |
i do have two dimentional array of data in php.
I do want to add another column with constant to that array for passing tabular data to next program.
i am iterating and adding manually. What can be alternate code?
my code:
if( is_array( $arrSource )){
foreach( $arrSource as &$dataRow){
... |
I wanted a pattern to manage web.config appsettings. I want to be able to have a default setting if the config setting was missing. I also wanted the check for the value in the config file to happen only once, not each time the the value is retrieved.
Public NotInheritable Class ExternalReportRequestBL
''' <summar... |
How can I improve this code for counting the number of bits of a positive integer n in Python?
def bitcount(n):
a = 1
while 1<<a <= n:
a <<= 1
s = 0
while a>1:
a >>= 1
if n >= 1<<a:
n >>= a
s += a
if n>0:
s += 1
return s
|
This is an alphabetical navigation which shows only the letter that have posts in both that letter and the currently filtered "genero" taxonomy term.
I use multiple taxonomy queries to find "artistas" posts that, for example, are tagged as both "rock" and "funk".
The function works perfectly and outputs exactly what I ... |
I'm wondering how I could refactor this code. It may look a little reiterative and probably there's a shorter method to accomplish the same.
def self.location(distance=100,location)
if distance.is_a? Integer
if distance.between?(1,5000)
distance = distance
elsif distance < 1
distance = 1
elsi... |
Basically trying to create a dict of all declared variables and functions along with their types of a .c source file. Does anyone think I missed anything?
#!usr/python
import string
import re
from types import *
from pprint import pprint
varDict = {}
def find_substring(needle, haystack):
index = haystack.find(nee... |
I have a a couple of different radio buttons which return an ethnicity and a gender. The script runs inside an internal application so rather than returning "boy", "girl" or "both" I get back 7707330, 7707333, and 7707336. Similar from the ethnicity radio button.
I then need to validate data based on the combonation o... |
I have method which checks period and return schedules:
public IEnumerable<EventSchedule> GetSchedulesForPeriod(PeriodEvent period, string tab = "")
{
switch (period)
{
case PeriodEvent.Today:
return GetTodaySchedules(tab);
case Period... |
If I want to strip a string completely of its whitespaces, punctuation and numbers (i.e. anything that is not A-Z, a-z), what is the most efficient way of doing it in C++?
I tried this:
string strip(string in) {
string final;
for(int i = 0; i < in.length(); i++) {
if(isalpha(in[i])) final += in[i];
... |
I took a little heat on a method I had to resize an image and I'm hoping I can get a little help on the best way to do it. This is intended for a simple Java Helper Library I'm developing. I have a few ways to do it.
New Method:
/**
* This method resizes the given image
*
* @param image
* @param width
* @param height
*... |
I have a class with approximately 140 menu buttons in a nested ribbon-style menu over a canvas type area within a WinForms application.
As a result of this, a large swathe of my codebehind file consists of 140 event handlers for click events.
Many of them however, are remarkable similar, for example:
private void b... |
Looking at a code review at work for a Win32 C# code I am seeing some lines like this:
int MinutesPerDay = 1440;
int MinutesPerWeek = 10080;
int MinutesPerMonth = 43200;
and so on ...
I am not sure what is wrong with it but still I feel this is not a good code and design? What do you guys think? Could he do it in a be... |
Here is a utility that supports ETL/merging in Entity Framework.
If it's not appealing as a general purpose tool, why?
If it is appealing as a general purpose tool, how might the design be made better?
Also, I'm not the world's most experienced programmer when it comes to writing re-usable code with paramaterized type... |
This is a fairly popular interview question that I conceptually understand but have never really attempted to implement. In other similar implementations of this in Java I have seen they typically operate on an array of boolean values which kind of irks me. It turns out that the way the JVM works however is that it wi... |
I have all these functions that work together to create functionality on a page. Is the structure of these functions OK? Can I do anything to speed this up or make my code better? I'm not exactly sure what namespaces are, but might they help me here?
This code is for a responsive/adaptive calendar website. On the hom... |
I'm attempting to create a comparison table to compare products depending on the add-ons they have. To grab the data and filter it I'm using LINQ To SQL.
Table's Layout (cut short):
Products Table
ID
Name
CategoryID
ProductAddons
Category Table
ID
Name
ProductAddon Table
ID
Amount
AddonID
ProductID
Addon Table
I... |
Firstly, apologies if this is not the correct type of question for here, I had it on the stackoverflow but it was closed with a suggestion I post here.
I’m in the process of converting from Latin 15 to Unicode/UTF-8 and researched several tutorials, and am looking here for a critique of what I have implemented based o... |
I have some code that loops over a number and populates a list using other lists. I think I can refactor it somehow to make it look nicer but not sure the best way to do it.
Here is the code:
for (int i = 0; i < loopCount; i++)
{
switch (NoOfRows)
{
case 1:
if (InputList1.Count > i)
... |
Assume that we have a .txt file that has one word per line.
Find out the word that occurs the most.
Here's what I was able to write (I used array of strings instead of a file in this example):
string[] source = { "test1", "test2", "test3", "test4", "test1", "test1", "test3" };
Dictionary<string, int> dic = source.Disti... |
Ok, I am in a JavaScript class, and I have no desire for anyone to do my schoolwork, I have already done what I think is correct, I am just hoping someone can take a look and tell me if I am close, or right, or whatever. Any feedback appreciated. Also, the instructor was very specific in saying that if it asks for a l... |
I have Django unit tests that are pretty much the following format:
class Tests(unittest.TestCase):
def check(self, i, j):
self.assertNotEquals(0, i-j)
for i in xrange(1, 4):
for j in xrange(2, 6):
def ch(i, j):
return lambda self: self.check(i, j)
setattr(Tests, "test_%r_%r... |
I have made the following classes and objects.
It was made to create forms programattically easily. It should produce highly readable, valid, and clean HTML.
Care to give me some feedback? :)
https://gist.github.com/2510553
Full code:
<?php
namespace Forms;
/**
* This file is supposed to give a good way of generating ... |
I am trying to improve my C skills, and I hope someone might be able to provide me with some feedback on the following code.
It is just basic string splitting, it should behave the similar to Ruby's String#split or Clojure's clojure.string.split. I couldn't think of a simple/efficient way to create an array of variable... |
I sometimes find myself wanting custom events on a global object with JQuery.
For example:
$(window).trigger('blah', {x: 'y'});
This plugin is designed to provide exactly that, except faster:
$.multicast('blah')({x: 'y'});
Full plugin code (minus test pages, really gotta get some qunit going on):
(function ($) {
... |
I'm using C# for a project and thought I would get a feel for the language by making some simple programs. My current program is a simple file recurser that prints the names of files and directories. Any suggestions would be greatly appreciated.
using System;
using System.IO;
namespace FileRecurser
{
class Progr... |
I've implementing the this algorithm in Java, Scala, and Clojure to show my teammates. I know the code works as expected. What I'm looking for is tips on good Clojure style.
(ns gaming.online.ranking
"Synopsis:
(bradley-terry-full 5
(list (create-team 1 45 (list (create-player 101 (create-ability-with... |
In the code below, I want to remove the "white space character" from 2 places only, from the end of 1st line and from the end of last line. How can I optimize it ?
Platform : Linux , gcc compiler
int remove_special_chars(char *file_path, char *dest_file, int flag)
{
PRINT_FUN_NAME
struct stat st;
unsig... |
This is my first attempt with MVC and I almost get it, but a small thing bothers me.
I have this controller in CodeIgniter:
<?php
class Page extends CI_Controller {
public function index($page = "home")
{
$data['page'] = $page;
list($data['title']) = array_keys($this->_menu(), $page);
... |
So I have convert the getDisplayPosition from the beta version of the Kinect SDK to the full version. Here's what I have right nowThe Original
private Point getDisplayPosition(Joint joint)
{
float depthX, depthY;
nui.SkeletonEngine.SkeletonToDepthImage(joint.Position, out depthX, out depthY);
... |
Any suggestions to make this better?
import math
# BSD License:
"""Copyright (c) 2012, Solomon Wise
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of so... |
I just finished rewriting my Router class. Any input would be much appreciated.
The class routes URLs based on a site.com/class/method/param/param/etc syntax.
One thing I've done differently is created a mechanism for basic templates to be loaded directly without the need for a controller. I often find pages such as /a... |
I am relatively new to jQuery and this is one of the first attempts to use it. Tell me if I am using it wrong:
This is the main code that toggles everything:
$(function(){
$("#tree li").hide();//collapse everything by default
$("#tree span").click(function(){
$(this).toggleClass("uncollapsed");//toggle... |
I'm creating a Java Helper Library with helpful static methods. I find myself needing to call ...getResource(...) or ...getResourceAsStream(...) in several instances and I'm wondering what's the best practice for this. It seems to be working fine when I say: Helper.class.getResource(...), but I'm wondering whether that... |
I'm not sure whether I should be throwing exceptions in the below model code (and rescuing in the controller - rescues not implemented below) or returning nil (in both or one of the exception cases). Also, should the model method be identify, or is identify proper?
My line of thinking is if the title is not set when id... |
My code is below. List anything that looks wrong, anything that could be improved. This is an update from this question. I know, my old code was a complete mess.
New Code:
import math
class ChangeableRange:
"""With this type of range object, one
can edit the start, stop, and step for the range, as well as easil... |
Suppose we are writing a GUI toolkit in C++ (though this question may also apply to other languages). We have a button class with a member function hide, which hides the button. This member function takes a Boolean parameter animated to control if the button should be hidden with an animation.
class Button {
public:
... |
I have an HTML table representing a database table and a sidebar which holds different anchors ready to perform CRUD operations on click.
Because the hrefs in the anchors aren't in general valid for all columns I have written a script which automatically inserts the id of a selected column into the hrefs:
/localhost/im... |
I'm working on an application that turns a raw camera image into a binary (pure black/white) image and I need this to happen as fast as possible for swift further processing. This is what my code currently looks like:
public static boolean[][] createBinaryImage( Bitmap bm )
{
int[] pixels = new int[bm.getWidth()*bm... |
A question of organization and best practices with Wordpress templates:
Where should I put my variables? Directly in the template? In a separate file via includes()?
Should I place all variables at the top of the template, or is it OK to mix them in with the HTML?
Should HTML be included directly in the variable, or i... |
I'm trying to learn Python through the excellent online book Dive Into Python 3. I have just finished chapter 2 about data types and felt like trying to write a program on my own.
The program takes an integer as input and factorizes it into prime numbers:
$ python main.py 6144
6144 -> (2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, ... |
I've just started with coffeescript, and I saw http://blog.8thlight.com/uncle-bob/2012/04/20/Why-Is-Estimating-So-Hard.html which has a little programming problem, so I figured I'd do it in coffeescript (which seemed easy enough to do... )
anyways, I ended up with :-
lineEndings = ( s, len ) ->
words = s.split ' ... |
Another stab at the Josephus problem, this time using Actors. N people stand in a circle and every stepth person is eliminated until one is remaining.
The way I solve it here is to give each actor a reference to their successor, and the actors send their successor a count of places since the last elimination. If an ac... |
I would be happy to hear feedback on my implementation of HttpClient. I am not so strong with error handling so I want to improve. My thought process behind this was that IOExceptions can be recoverable and should be tried again. Where as client exception isn't. Hope to hear your thoughts.
private HttpResponse execute(... |
Is there a way to reduce the number of lines by setting the output variable inside LINQ select statement? How would you do it?
public void GetSomeValue(int bonusID, out decimal? maxGiving, out int? isActive)
{
maxGiving = 0;
isActive = 0;
try
{
var con = new BonusModelDataContext();
var ... |
I have been working on a Backbone.js application, and I am starting to think I am making a huge mistake.
I never fully understand garbage collecting, and how exactly some closures prevent it. I just try to keep as organized as possible.
I just read an article that states that JavaScript variables that are not declared ... |
I have an HTML table representing a database table and a sidebar which holds different anchors ready to perform CRUD operations on click.
Because the hrefs in the anchors aren't general valid for all columns I have written a script which automatically inserts the id of a selected column into the hrefs:
/localhost/image... |
This allows users to upload an file from the browser into my Rails app using the paperclip gem. Once the file is uploaded it gets saved into the filesystem. When the user then goes in and the "show" method or the "edit" method is evoked the image is shown to the user. This is fine for image files but for .csv and .txt ... |
I've written a script that deletes a member of a hash if an array within the has contains all the other elements of another array within the same hash.
It works but it looks a little messy. Is there a better way to do this?
def title_contains_blocks(candidate, titles, index)
test_group = titles.dup
test_group.delet... |
This hides div.extended then creates a button that toggles its text and div.extended's visibility.
While the below works, I was wondering if there was a more concise way of writing this code.
(function() {
var extended = $('.extended').hide();
$('<button></button>', {
text: 'Read more'
}).appendTo('.intro')
... |
Though it works I wonder if there might be a better way to do this. I would like to reuse this loading and establishing of fields of another class(es) (the static TileMapper class mentioned at the end) in a C#/.net/XNA environment.
I noticed that when moving through the OpenFileDialog to find files it felt sluggish.
I... |
I have a class bar that keeps track of N instances of class foo in a std::map (so N = map.size()).
When I call bar::func I want to have N threads that call foo::foo_func.
foo::foo_func requires multiple arguments though, namely the instance of bar that it's related to.
I was thinking of doing something like:
void * _th... |
I am making an interpreter for a custom programming language (concatenative, soft-typed) and for that purpose I have a central datatype Token. A Token can be of one of the many different types, either of scalar ones or vector ones. To minimize the amount of memory, I used a union first but then I could only use plain-o... |
I just recently learned how to use Bit Field Structures in C++, and I was thinking of applying it to a project. It would certainly make the project code much easier to work with. So, I typed up a quick test program to see if it would work as I expected, and it does. But, I'm not 100% convinced that it is safe.
I am fa... |
I know it's been done a million times already, but I couldn't find a serialization library to suit my needs. This is the very basis of what I came up with. I know the code is ugly and unstructured, so you don't have to tell me that.
My goal is to make a serialization/deserialization system that provides a minimal, opti... |
Here is what I have. A User model and an Address model. User has_many :addresses and Address belongs_to :user.
Now I want to search for users whose email contains a give term, or one of the user's addresses contains that term. So lets say the term is 'jap', any User whose email like '%jap%' or any user whose any addres... |
Do you have any suggestions about how to make this code faster/better? Maybe suggest new features or better comments/docstrings?
from time import time, ctime, sleep
from random import choice, uniform
from glob import glob
import os
# Gets current working directory
DIRECTORY_NAME = os.getcwd()
def load():
""... |
I was looking for a solution to allow me to rate limit the number of outgoing REST calls but preserved the order of queued elements so I found a rate limiter implementation and combined it with ConcurrentQueue<T>.
Improvements/critique?
Version 2 after assimilating svick's comments and adding a Unit Test
Throttle class... |
I previously posted my first attempt at writing a program that I was given to test my skills for a position that I was interviewing for. I have rewritten the program using the excellent advice that I received from that posting and I also started reading a book on Java Objects.
I would like to see if I am getting a bet... |
I'm writing a program to build and solve a Maze using DFS and backtracking using Java Swing. The code was a mess when I have to put my logic into my JPanel in order to show animation via the call to repaint(). Here are all classes:
Point
public class Point {
public int mX;
public int mY;
public Point(int ... |
I have found that writing unit tests helps me to discover both the intent and also reusability of code that I'm working on. It has been generally helpful in helping develop my "code smell."
I was working on two unit tests that are basically mirror images, and realized that I was typing code that looked almost identical... |
I have recently made a small program to generate D&D (original edition) monster stat blocks in text form. I use this program myself to generate stats block so that I can then copy and paste them in the adventures I am writing.
The main reason for using a program is to have the program roll the random values.
Here is an... |
How can I make this piece of code better? The problem to be solved is in the topmost comment.
#include <iostream>
#include <vector>
#include <cassert>
#include <stdint.h>
#include <iterator>
#include <queue>
/*
* Shuttle Puzzle:
* A Shuttle Puzzle of size 4 consists of 4 white marbles, 4 black marbles, and a strip o... |
This code achieves the effect, but is it a resource friendly way of doing it?
Just to clarify: target div.fixMe and fix it to the top of the window when the user scrolls past its natural position. (I do realise there are plugins to achieve this result, but I wanted to build it myself)
Is this the best way to achieve th... |
Hope that title makes sense.
This is part of an object I have:
The event listener attaches to the correct marker passed in the parameter but inside the function, this points to something else.
function UserGoogleMap($mapElement) {
this.$mapElement = $mapElement;
this.map = {};
this.marker = null;
this.... |
Here's a program I wrote to sort a list of numbers in increasing order (without using inbuilt sort function).
(define (sort-list l)
(define first-element (if (not (null? l)) (car l) 0))
(cond ((null? l) (quote ()))
(else (cons (find-shortest l first-element) (sort-list (remove-member l (find-shortest l firs... |
Here is my implementation of the greedy algorithim in Ruby. Do you have any suggestions?
class Greedy
def initialize(unit, total, *coins)
@total_coins = 0
@unit = unit
@total = total
@currency = coins.sort
@currency = @currency.reverse
unless @currency.include?(1)
@currency.push(1)
e... |
I have written a custom drop down menu handler using jQuery because I felt that the native drop down didn't fit my UI. I have taking into consideration the native way of going through a drop down box using arrows and tabs to move to next input.
I was wondering if anyone can see any mistakes or errors or anyway I could ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.