Daily Archives

Articles indexed Saturday October 26 2013

Page 11/15 | < Previous Page | 7 8 9 10 11 12 13 14 15  | Next Page >

  • Sphere entering in to the cube.unity

    - by Parthi
    I am trying Roll a Ball unity tutorial.Everything is fine,but when I roll the ball it is moving through the cube instead of picking it. my player class is using UnityEngine; using System.Collections; public class player : MonoBehaviour { public float speed; // Use this for initialization // Update is called once per frame void Update () { float h = Input.GetAxis("Horizontal"); float v = Input.GetAxis("Vertical"); Vector3 move = new Vector3(h,0,v); rigidbody.AddForce(move * speed * Time.deltaTime); } void OnTriggerEnter(Collider other) { if(other.gameObject.tag == "Pick up") { other.gameObject.SetActive(false); } } }

    Read the article

  • Good 3D Game Engine for the Horror Genre [on hold]

    - by James Wassall
    I am starting to think about and design (pencil drawings) a simple, horror game. I'm in need of a good engine which supports features like Dynamic Lighting (for a characters flashlight) and dynamic shadows. My first choice was obviously Unity3D, as its free and is (supposedly) the easiest to use. However, I believe that a lot of features are locked for the Pro version (a $1500 investment). Is there any good, free engines that support dynamic events? I have read a lot of posts recommending the Source engine but I don't want to make a mod, I would like to make a fully featured standalone game. I'm not looking for opinions on "Which engine you prefer" or "Which engine do you use", all I would like is to be presented with the facts. -James

    Read the article

  • Proper updating of GeoClipMaps

    - by thr
    I have been working on an implementation of gpu-based geo clip maps, but there is a section of the GPU Gems 2 article that i just can't seem to understand, specifically this paragraph and more precisely the bolded part: The choice of grid size n = 2k-1 has the further advantage that the finer level is never exactly centered with respect to its parent next-coarser level. In other words, it is always offset by 1 grid unit either left or right, as well as either top or bottom (see Figure 2-4), depending on the position of the viewpoint. In fact, it is necessary to allow a finer level to shift while its next-coarser level stays fixed, and therefore the finer level must sometimes be off-center with respect to the next-coarser level. An alternative choice of grid size, such as n = 2k-3, would provide the possibility for exact centering Let's take an example image from the article: My "understanding" of the way the clip maps were update was that you floor the position of the viewpoint to an int, and such get the center vertex point if this is not the same as the previous center point, you update the entire map. Now, this obviously is not the case - but what I am failing to understand is this: If you look at the image above, if the viewpoint was to move one unit to the right, then the inner ring (the one just around the view point + white center square) would end up getting a 1 unit space on both the left and right side of itself. But there is nothing in the paper that deals with this, what i mean is that it would end up looking like this (excuse my crummy cut-and-paste editing of the above image): This is obviously not a valid state of the. So, would the solution be that a clip ring (layer) can only move in increments of the ring/layer it's contained within? Wouldn't this end up being very restrictive? I feel like I am missing some crucial understanding of parts of the algorithm, but I have been over both this paper and the original paper from 2004 and I just can't see what I am not getting.

    Read the article

  • LINQ Query returns false when it should be true.

    - by deliriousDev
    I have the following LINQ query written by a former developer and it isn't working when it should. public bool IsAvailable(Appointment appointment) { var appointments = _appointmentRepository.Get; var shifts = _scheduleRepository.Get; var city = _customerRepository.Find(appointment.CustomerId).City ?? appointment.Customer.City; const int durationHour = 1; DateTime scheduledEndDate = appointment.ScheduledTime.Add(new TimeSpan(durationHour, 0, 0)); var inWorkingHours = shifts .Where(x => //Check if any available working hours x.Employee.City == city && x.ShiftStart <= appointment.ScheduledTime && x.ShiftEnd >= scheduledEndDate && //check if not booked yet !appointments .Where(a => (appointment.Id == 0 || a.Id != appointment.Id) && a.Employee.Id == x.Employee.Id && ( (a.ScheduledTime <= appointment.ScheduledTime && appointment.ScheduledTime <= EntityFunctions.AddHours(a.ScheduledTime, durationHour)) || (a.ScheduledTime <= scheduledEndDate && scheduledEndDate <= EntityFunctions.AddHours(a.ScheduledTime, durationHour)) )) .Select(a => a.Employee.Id) .Contains(x.Employee.Id) ); if (inWorkingHours.Any()) { var assignedEmployee = inWorkingHours.FirstOrDefault().Employee; appointment.EmployeeId = assignedEmployee.Id; appointment.Employee = assignedEmployee; return true; } return false; } The query is suppose to handle the following scenarios Given An Appointment With A ScheduledTime Between A ShiftStart and ShiftEnd time But Does not match any employees in same city - (Return true, Assign as "Unassigned") Given An Appointment With A ScheduledTime Between A ShiftStart and ShiftEnd time AND Employee for that shift is in the same city as the customer (Return True AND Assign to the employee) If the customer is NOT in the same city as an employee we assign the appointment as "Unassigned" as along as the scheduledTime is within an of the employees shift start/end times If the customer is in the same city as an employee we assign the appointment to one of the employees (firstOrdefault) and occupy that timeslot. Appointments CAN NOT overlap (Assigned Ones). Unassigned can't overlap each other. This query use to work (I've been told). But now it doesn't and I have tried refactoring it and various other paths with no luck. I am now on week two and just don't know where the issue in the query is or how to write it. Let me know if I need to post anything further. I have verified appointments, shifts, city all populate with valid data so the issue doesn't appear to be with null or missing data.

    Read the article

  • angular custom directive required validation is not updated

    - by Wouter Willems
    i created my own directive, replacing an input field with a custom made input field. However, the validation of the required field never seems to update and instead is always false. Other directives inside my directive like ng-class do work. I have created a plunker here to show this problem: http://plnkr.co/edit/NuZNAJceL0MVX8i6RK9n?p=preview Can anybody help me out how to make sure that the required validation is properly updated?

    Read the article

  • Problems in Binary Search Tree

    - by user2782324
    This is my first ever trial at implementing the BST, and I am unable to get it done. Please help The problem is that When I delete the node if the node is in the right subtree from the root or if its a right child in the left subtree, then it works fine. But if the node is in the left subtree from root and its any left child, then it does not get deleted. Can someone show me what mistake am I doing?? the markedNode here gets allocated to the parent node of the node to be deleted. the minValueNode here gets allocated to a node whose left value child is the smallest value and it will be used to replace the value to be deleted. package DataStructures; class Node { int value; Node rightNode; Node leftNode; } class BST { Node rootOfTree = null; public void insertintoBST(int value) { Node markedNode = rootOfTree; if (rootOfTree == null) { Node newNode = new Node(); newNode.value = value; rootOfTree = newNode; newNode.rightNode = null; newNode.leftNode = null; } else { while (true) { if (value >= markedNode.value) { if (markedNode.rightNode != null) { markedNode = markedNode.rightNode; } else { Node newNode = new Node(); newNode.value = value; markedNode.rightNode = newNode; newNode.rightNode = null; newNode.leftNode = null; break; } } if (value < markedNode.value) { if (markedNode.leftNode != null) { markedNode = markedNode.leftNode; } else { Node newNode = new Node(); newNode.value = value; markedNode.leftNode = newNode; newNode.rightNode = null; newNode.leftNode = null; break; } } } } } public void searchBST(int value) { Node markedNode = rootOfTree; if (rootOfTree == null) { System.out.println("Element Not Found"); } else { while (true) { if (value > markedNode.value) { if (markedNode.rightNode != null) { markedNode = markedNode.rightNode; } else { System.out.println("Element Not Found"); break; } } if (value < markedNode.value) { if (markedNode.leftNode != null) { markedNode = markedNode.leftNode; } else { System.out.println("Element Not Found"); break; } } if (value == markedNode.value) { System.out.println("Element Found"); break; } } } } public void deleteFromBST(int value) { Node markedNode = rootOfTree; Node minValueNode = null; if (rootOfTree == null) { System.out.println("Element Not Found"); return; } if (rootOfTree.value == value) { if (rootOfTree.leftNode == null && rootOfTree.rightNode == null) { rootOfTree = null; return; } else if (rootOfTree.leftNode == null ^ rootOfTree.rightNode == null) { if (rootOfTree.rightNode != null) { rootOfTree = rootOfTree.rightNode; return; } else { rootOfTree = rootOfTree.leftNode; return; } } else { minValueNode = rootOfTree.rightNode; if (minValueNode.leftNode == null) { rootOfTree.rightNode.leftNode = rootOfTree.leftNode; rootOfTree = rootOfTree.rightNode; } else { while (true) { if (minValueNode.leftNode.leftNode != null) { minValueNode = minValueNode.leftNode; } else { break; } } // Minvalue to the left of minvalue node rootOfTree.value = minValueNode.leftNode.value; // The value has been swapped if (minValueNode.leftNode.leftNode == null && minValueNode.leftNode.rightNode == null) { minValueNode.leftNode = null; } else { if (minValueNode.leftNode.leftNode != null) { minValueNode.leftNode = minValueNode.leftNode.leftNode; } else { minValueNode.leftNode = minValueNode.leftNode.rightNode; } // Minvalue deleted } } } } else { while (true) { if (value > markedNode.value) { if (markedNode.rightNode != null) { if (markedNode.rightNode.value == value) { break; } else { markedNode = markedNode.rightNode; } } else { System.out.println("Element Not Found"); return; } } if (value < markedNode.value) { if (markedNode.leftNode != null) { if (markedNode.leftNode.value == value) { break; } else { markedNode = markedNode.leftNode; } } else { System.out.println("Element Not Found"); return; } } } // Parent of the required element found // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// if (markedNode.rightNode != null) { if (markedNode.rightNode.value == value) { if (markedNode.rightNode.rightNode == null && markedNode.rightNode.leftNode == null) { markedNode.rightNode = null; return; } else if (markedNode.rightNode.rightNode == null ^ markedNode.rightNode.leftNode == null) { if (markedNode.rightNode.rightNode != null) { markedNode.rightNode = markedNode.rightNode.rightNode; return; } else { markedNode.rightNode = markedNode.rightNode.leftNode; return; } } else { if (markedNode.rightNode.value == value) { minValueNode = markedNode.rightNode.rightNode; } else { minValueNode = markedNode.leftNode.rightNode; } if (minValueNode.leftNode == null) { // MinNode has no left value markedNode.rightNode = minValueNode; return; } else { while (true) { if (minValueNode.leftNode.leftNode != null) { minValueNode = minValueNode.leftNode; } else { break; } } // Minvalue to the left of minvalue node if (markedNode.leftNode != null) { if (markedNode.leftNode.value == value) { markedNode.leftNode.value = minValueNode.leftNode.value; } } if (markedNode.rightNode != null) { if (markedNode.rightNode.value == value) { markedNode.rightNode.value = minValueNode.leftNode.value; } } // MarkedNode exchanged if (minValueNode.leftNode.leftNode == null && minValueNode.leftNode.rightNode == null) { minValueNode.leftNode = null; } else { if (minValueNode.leftNode.leftNode != null) { minValueNode.leftNode = minValueNode.leftNode.leftNode; } else { minValueNode.leftNode = minValueNode.leftNode.rightNode; } // Minvalue deleted } } } // //////////////////////////////////////////////////////////////////////////////////////////////////////////////// if (markedNode.leftNode != null) { if (markedNode.leftNode.value == value) { if (markedNode.leftNode.rightNode == null && markedNode.leftNode.leftNode == null) { markedNode.leftNode = null; return; } else if (markedNode.leftNode.rightNode == null ^ markedNode.leftNode.leftNode == null) { if (markedNode.leftNode.rightNode != null) { markedNode.leftNode = markedNode.leftNode.rightNode; return; } else { markedNode.leftNode = markedNode.leftNode.leftNode; return; } } else { if (markedNode.rightNode.value == value) { minValueNode = markedNode.rightNode.rightNode; } else { minValueNode = markedNode.leftNode.rightNode; } if (minValueNode.leftNode == null) { // MinNode has no left value markedNode.leftNode = minValueNode; return; } else { while (true) { if (minValueNode.leftNode.leftNode != null) { minValueNode = minValueNode.leftNode; } else { break; } } // Minvalue to the left of minvalue node if (markedNode.leftNode != null) { if (markedNode.leftNode.value == value) { markedNode.leftNode.value = minValueNode.leftNode.value; } } if (markedNode.rightNode != null) { if (markedNode.rightNode.value == value) { markedNode.rightNode.value = minValueNode.leftNode.value; } } // MarkedNode exchanged if (minValueNode.leftNode.leftNode == null && minValueNode.leftNode.rightNode == null) { minValueNode.leftNode = null; } else { if (minValueNode.leftNode.leftNode != null) { minValueNode.leftNode = minValueNode.leftNode.leftNode; } else { minValueNode.leftNode = minValueNode.leftNode.rightNode; } // Minvalue deleted } } } } // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// } } } } } } public class BSTImplementation { public static void main(String[] args) { BST newBst = new BST(); newBst.insertintoBST(19); newBst.insertintoBST(13); newBst.insertintoBST(10); newBst.insertintoBST(20); newBst.insertintoBST(5); newBst.insertintoBST(23); newBst.insertintoBST(28); newBst.insertintoBST(16); newBst.insertintoBST(27); newBst.insertintoBST(9); newBst.insertintoBST(4); newBst.insertintoBST(22); newBst.insertintoBST(17); newBst.insertintoBST(30); newBst.insertintoBST(40); newBst.deleteFromBST(5); newBst.deleteFromBST(4); newBst.deleteFromBST(9); newBst.deleteFromBST(10); newBst.deleteFromBST(13); newBst.deleteFromBST(16); newBst.deleteFromBST(17); newBst.searchBST(5); newBst.searchBST(4); newBst.searchBST(9); newBst.searchBST(10); newBst.searchBST(13); newBst.searchBST(16); newBst.searchBST(17); System.out.println(); newBst.deleteFromBST(20); newBst.deleteFromBST(23); newBst.deleteFromBST(27); newBst.deleteFromBST(28); newBst.deleteFromBST(30); newBst.deleteFromBST(40); newBst.searchBST(20); newBst.searchBST(23); newBst.searchBST(27); newBst.searchBST(28); newBst.searchBST(30); newBst.searchBST(40); } }

    Read the article

  • Java 2D clip area to shape

    - by user2923880
    I'm quite new to graphics in java and I'm trying to create a shape that clips to the bottom of another shape. Here is an example of what I'm trying to achieve: Where the white line at the base of the shape is the sort of clipped within the round edges. The current way I am doing this is like so: g2.setColor(gray); Shape shape = getShape(); //round rectangle g2.fill(shape); Rectangle rect = new Rectangle(shape.getBounds().x, shape.getBounds().y, width, height - 3); Area area = new Area(shape); area.subtract(new Area(rect)); g2.setColor(white); g2.fill(area); I'm still experimenting with the clip methods but I can't seem to get it right. Is this current method ok (performance wise, since the component repaints quite often) or is there a more efficient way? Thanks in advance.

    Read the article

  • When I try to redefine a variable, I get an index out of bounds error

    - by user2770254
    I'm building a program to act as a calculator with memory, so you can give variables and their values. Whenever I'm trying to redefine a variable, a = 5, to a = 6, I get an index out of bounds error. public static void main(String args[]) { LinkedHashMap<String,Integer> map = new LinkedHashMap<String,Integer>(); Scanner scan = new Scanner(System.in); ArrayList<Integer> values = new ArrayList<>(); ArrayList<String> variables = new ArrayList<>(); while(scan.hasNextLine()) { String line = scan.nextLine(); String[] tokens = line.split(" "); if(!Character.isDigit(tokens[0].charAt(0)) && !line.equals("clear") && !line.equals("var")) { int value = 0; for(int i=0; i<tokens.length; i++) { if(tokens.length==3) { value = Integer.parseInt(tokens[2]); System.out.printf("%5d\n",value); if(map.containsKey(tokens[0])) { values.set(values.indexOf(tokens[0]), value); variables.set(variables.indexOf(tokens[0]), tokens[0]); } else { values.add(value); } break; } else if(tokens[i].charAt(0) == '+') { value = addition(tokens, value); System.out.printf("%5d\n",value); variables.add(tokens[0]); if(map.containsKey(tokens[0])) { values.set(values.indexOf(tokens[0]), value); variables.set(variables.indexOf(tokens[0]), tokens[0]); } else { values.add(value); } break; } else if(i==tokens.length-1 && tokens.length != 3) { System.out.println("No operation"); break; } } map.put(tokens[0], value); } if(Character.isDigit(tokens[0].charAt(0))) { int value = 0; if(tokens.length==1) { System.out.printf("%5s\n", tokens[0]); } else { value = addition(tokens, value); System.out.printf("%5d\n", value); } } if(line.equals("clear")) { clear(map); } if(line.equals("var")) { variableList(variables, values); } } } public static int addition(String[] a, int b) { for(String item : a) { if(Character.isDigit(item.charAt(0))) { int add = Integer.parseInt(item); b = b + add; } } return b; } public static void clear(LinkedHashMap<String,Integer> b) { b.clear(); } public static void variableList(ArrayList<String> a, ArrayList<Integer> b) { for(int i=0; i<a.size(); i++) { System.out.printf("%5s: %d\n", a.get(i), b.get(i)); } } I included the whole code because I'm not sure where the error is arising from.

    Read the article

  • CGAffineTransformMakeRotation goes the other way after 180 degrees (-3.14)

    - by TheKillerDev
    So, i am trying to do a very simple disc rotation (2d), according to the user touch on it, just like a DJ or something. It is working, but there is a problem, after certain amount of rotation, it starts going backwards, this amount is after 180 degrees or as i saw in while logging the angle, -3.14 (pi). I was wondering, how can i achieve a infinite loop, i mean, the user can keep rotating and rotating to any side, just sliding his finger? Also a second question is, is there any way to speed up the rotation? Here is my code right now: #import <UIKit/UIKit.h> @interface Draggable : UIImageView { CGPoint firstLoc; UILabel * fred; double angle; } @property (assign) CGPoint firstLoc; @property (retain) UILabel * fred; @end @implementation Draggable @synthesize fred, firstLoc; - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; angle = 0; if (self) { // Initialization code } return self; } -(void)handleObject:(NSSet *)touches withEvent:(UIEvent *)event isLast:(BOOL)lst { UITouch *touch =[[[event allTouches] allObjects] lastObject]; CGPoint curLoc = [touch locationInView:self]; float fromAngle = atan2( firstLoc.y-self.center.y, firstLoc.x-self.center.x ); float toAngle = atan2( curLoc.y-(self.center.y+10), curLoc.x-(self.center.x+10)); float newAngle = angle + (toAngle - fromAngle); NSLog(@"%f",newAngle); CGAffineTransform cgaRotate = CGAffineTransformMakeRotation(newAngle); self.transform = cgaRotate; if (lst) angle = newAngle; } -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch =[[[event allTouches] allObjects] lastObject]; firstLoc = [touch locationInView:self]; }; -(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { [self handleObject:touches withEvent:event isLast:NO]; }; -(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { [self handleObject:touches withEvent:event isLast:YES]; } @end And in the ViewController: UIImage *tmpImage = [UIImage imageNamed:@"theDisc.png"]; CGRect cellRectangle; cellRectangle = CGRectMake(-1,self.view.frame.size.height,tmpImage.size.width ,tmpImage.size.height ); dragger = [[Draggable alloc] initWithFrame:cellRectangle]; [dragger setImage:tmpImage]; [dragger setUserInteractionEnabled:YES]; dragger.layer.anchorPoint = CGPointMake(.5,.5); [self.view addSubview:dragger]; I am open to new/cleaner/more correct ways of doing this too. Thanks in advance.

    Read the article

  • Template inheritance: X is not a template

    - by user2923917
    I am trying to build a inheritance-structure which looks like: Base - template Grandpa - template Father class Base {}; template <int x> class Grandpa: public Base {}; template <int x> class Father: public Grandpa<x> {}; However, the compiler complains when compiling Father, that Grandpa is not a template. I guess it is just some synthatic issue, however everything I've tried so far led to even more compiler complaints ;) Any idea whats wrong?

    Read the article

  • Multiple dex files define Lcom/google/api/client/auth/oauth/AbstractOAuthGetToken;

    - by Elad Benda
    I have just followed this tutorial: https://developers.google.com/drive/quickstart-android so I don't see a reason for duplicated libs in my project. I have added the drive Client lib via Google plugin for eclipse When I build my android app with this manifest <uses-sdk android:minSdkVersion="15" android:targetSdkVersion="16" /> <uses-permission android:name="android.permission.READ_CALENDAR" /> <uses-permission android:name="android.permission.WRITE_CALENDAR" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.GET_ACCOUNTS"/> <uses-permission android:name="android.permission.INTERNET" /> <application android:icon="@drawable/todo" android:label="@string/app_name" > <activity android:name=".TodosOverviewActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".TodoDetailActivity" android:windowSoftInputMode="stateVisible|adjustResize" > <intent-filter> <action android:name="android.intent.action.SEND" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="image/*" /> </intent-filter> </activity> <provider android:name=".contentprovider.MyTodoContentProvider" android:authorities="de.vogella.android.todos.contentprovider" > </provider> </application> I get the following error: [2013-10-27 00:43:58 - Dex Loader] Unable to execute dex: Multiple dex files define Lcom/google/api/client/auth/oauth/AbstractOAuthGetToken; [2013-10-27 00:43:58 - de.vogella.android.todos] Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lcom/google/api/client/auth/oauth/AbstractOAuthGetToken; how can I fix this?

    Read the article

  • Extend a direct instance

    - by Diolor
    We have a new instance of an object with four properties: person={firstname:"John",lastname:"Doe",age:50,eyecolor:"blue"}; What is the best way to many other properties to that object? If we wanted few couple more sure we would: person[address_no] = 4; .... person[country] = 'Netherlands'; But what if we have a lot properties. Is there any minimalistic way like the one below? (I know it doesn't work) person +={address_no: '4', .... , country: 'Netherlands'};

    Read the article

  • Does INNER JOIN performance depends on order of tables?

    - by Kartic
    A question suddenly came to my mind while I was tuning one stored procedure. Let me ask it - I have two tables, table1 and table2. table1 contains huge data and table2 contains less data. Is there performance-wise any difference between these two queries(I am changing order of the tables)? Query1: SELECT t1.col1, t2.col2 FROM table1 t1 INNER JOIN table2 t2 ON t1.col1=t2.col2 Query2: SELECT t1.col1, t2.col2 FROM table2 t2 INNER JOIN table1 t1 ON t1.col1=t2.col2 We are using Microsoft SQL server 2005.

    Read the article

  • sed - trying to replace first occurrence after a match

    - by wakkaluba
    I am facing a situation that drives me nuts. I am setting up an update server which uses a json file. Don't ask why or how, it sucks and is my only possibility to achieve it. I have been trying and researching for HOURS (many) because I went ballistic and wanted to crack this on my own. But I have to realize I got stuck and need help. So sorry for this chunk but I think it is somewhat important to see... The file is a one liner and repeating the following sequence with changing values (of course). "plugin_name_foo_bar": {"buildDate": "bla", "dependencies": [{"name": "bla", "optional": true, "version": "1.00"}], "developers": [{"developerId": "bla", "email": "[email protected]", "name": "Bla bla2nd"}], "excerpt": "some text {excerpt} !bla.png|thumbnail,border=1! ", "gav": "bla", "labels": ["report", "scm-related"], "name": "plugin_name_foo_bar", "previousTimestamp": "bla", "previousVersion": "1.0", "releaseTimestamp": "bla", "requiredCore": "1", "scm": "github.com", "sha1": "ynnBM2jWo25ZLDdP3ybBOnV/Pio=", "title": "bla", "url": "http://bla.org", "version": "1.0", "wiki": "https://bla.org"}, "Exclusion": {"buildDate": "bla", "dependencies": [], and the next plugin block is glued straight afterwards. What I now want to do is to search for "plugin_foo_bar": {" as this is the unique identifier for a new plugin description block. I want to replace the first sha1 value occuring afterwards. That's where I keep failing. I always grab the first,last or any occurrence in the entire file and not the block :( "title" is the unique identifier after the sha1 value. So I tried to make the .* less greedy but it ain't working out. last attempt was heading towards: sed -i 's/("name": "plugin_name_foo_bar.*sha1": ")([a-zA-Z0-9!@#\$%^&*()\[\]]*)(", "title"\)/\1blablabla\2/1' default.json to find the sha1 value of that plugin but still no joy. I hope someone knows - preferably a simpler approach - before I now continue with trial and error until I have to puke and freakout. I am working with SED on Windows, so Unix approach might help me to figure out how to achieve this in batch but please make it as one-liner if possible. Scripts are a real pain to convert. And I just need SED and no other solution with other tools like AWK. That is absolutely out of discussion. Any help is appreciated :) Cheers Jan

    Read the article

  • Creating search functionality with Laravel 4

    - by Mitch Glenn
    I am trying to create a way for users to search through all the products on a website. When they search for "burton snowboards", I only want the snowboards with the brand burton to appear in the results. But if they searched only "burton", then all products with the brand burton should appear. This is what I have attempted to write but isn't working for multiple reasons. Controller: public function search(){ $input = Input::all(); $v= Validator::make($input, Product::$rules); if($v->passes()) { $searchTerms = explode(' ', $input); $searchTermBits = array(); foreach ($searchTerms as $term) { $term = trim($term); if (!empty($term)){ $searchTermBits[] = "search LIKE '%$term%'"; } } $result = DB::table('products') ->select('*') ->whereRaw(". implode(' AND ', $searchTermBits) . ") ->get(); return View::make('layouts/search', compact('result')); } return Redirect::route('/'); } I am trying to recreate the first solution given for this stackoverflow.com problem The first problem I have identified is that i'm trying to explode the $input, but it's already an array. So i'm not sure how to go about fixing that. And the way I have written the ->whereRaw(". implode(' AND ', $searchTermBits) . "), i'm sure isn't correct. I'm not sure how to fix these problems though, any insights or solutions will be greatly appreciated.

    Read the article

  • how do i round/trucate a number without using methods like math.round or %3f?

    - by user2923875
    So far I need to round a number that I inputted and get it to 3 decimal places without those methods. if(number !=(int)number){ number*=1000; number=(int)number; number=(double)number; number/=1000; System.out.println("-"+ number); } if(number ==(int)number){ System.out.println("-"+ number + "00"); } With that above, it will work for any input except the ones with 2 decimal places, like 12.34 . How do I make it work if i type 12.34 and displays 12.340?

    Read the article

  • Python MQTT: TypeError: coercing to Unicode: need string or buffer, bool found

    - by user2923860
    When my python code tries to connect to the MQTT broker it gives me this Type Error: Update- I added the Complete Error Traceback (most recent call last): File "test.py", line 20, in <module> mqttc.connect(broker, 1883, 60, True) File "/usr/local/lib/python2.7/dist-packages/mosquitto.py", line 563, in connect return self.reconnect() File "/usr/local/lib/python2.7/dist-packages/mosquitto.py", line 632, in reconnect self._sock = socket.create_connection((self._host, self._port), source_address=(self._bind_address, 0)) File "/usr/lib/python2.7/socket.py", line 561, in create_connection sock.bind(source_address) File "/usr/lib/python2.7/socket.py", line 224, in meth return getattr(self._sock,name)(*args) TypeError: coercing to Unicode: need string or buffer, bool found The code of the python file is: #! /usr/bin/python import mosquitto broker = "localhost" #define what happens after connection def on_connect(rc): print "Connected" #On recipt of a message do action def on_message(msg): n = msg.payload t = msg.topic if t == "/test/topic": if n == "test": print "test message received" # create broker mqttc = mosquitto.Mosquitto("python_sub") #define callbacks mqttc.on_message = on_message mqttc.on_connect = on_connect #connect mqttc.connect(broker, 1883, 60, True) #Subscribe to topic mqttc.subscribe("/test/topic", 2) #keep connected while mqttc.loop() == 0: pass I have no idea why its giving me this it work 2 days ago.

    Read the article

  • opengl, Black lines in-between tiles

    - by MiJyn
    When its translated in an integral value (1,2,3, etc....), there are no black lines in-between the tiles, it looks fine. But when it's translated to a non-integral (1.1, 1.5, 1.67), there are small blackish lines between each tile (I'm imagining that it's due to subpixel rendering, right?) ... and it doesn't look pretty =P So... what should I do? This is my image-loading code, by the way: bool Image::load_opengl() { this->id = 0; glGenTextures(1, &this->id); this->bind(); // Parameters... TODO: Should we change this? glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, this->size.x, this->size.y, 0, GL_BGRA, GL_UNSIGNED_BYTE, (void*) FreeImage_GetBits(this->data)); this->unbind(); return true; } I've also tried using: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); and: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); Here is my image drawing code: void Image::draw(Pos pos, CROP crop, SCALE scale) { if (!this->loaded || this->id == 0) { return; } // Start position & size Pos s_p; Pos s_s; // End size Pos e_s; if (crop.active) { s_p = crop.pos / this->size; s_s = crop.size / this->size; //debug("%f %f", s_s.x, s_s.y); s_s = s_s + s_p; s_s.clamp(1); //debug("%f %f", s_s.x, s_s.y); } else { s_s = 1; } if (scale.active) { e_s = scale.size; } else if (crop.active) { e_s = crop.size; } else { e_s = this->size; } // FIXME: Is this okay? s_p.y = 1 - s_p.y; s_s.y = 1 - s_s.y; // TODO: Make this use VAO/VBO's!! glPushMatrix(); glTranslate(pos.x, pos.y, 0); this->bind(); glBegin(GL_QUADS); glTexCoord2(s_p.x, s_p.y); glVertex2(0, 0); glTexCoord2(s_s.x, s_p.y); glVertex2(e_s.x, 0); glTexCoord2(s_s.x, s_s.y); glVertex2(e_s.x, e_s.y); glTexCoord2(s_p.x, s_s.y); glVertex2(0, e_s.y); glEnd(); this->unbind(); glPopMatrix(); } OpenGL Initialization code: void game__gl_init() { glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0.0, config.window.size.x, config.window.size.y, 0.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glDisable(GL_DEPTH_TEST); glEnable(GL_BLEND); glEnable(GL_TEXTURE_2D); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } Screenshots of the issue:

    Read the article

  • Context-sensitive grammar for specific language

    - by superagio
    How can I construct a grammar that generates this language? Construct a grammar that generates L: L = {a^n b^m c^k|k>n, k>m} I believe my productions should go along this lines: S-> ABCC A-> a|aBC|BC B-> b|bBC C-> c|Cc CB->BC The idea is to start with 2 c and keep always one more c, and then with C-c|Cc ad as much c as i want. How can my production for C remember the numbers of m and n.

    Read the article

  • Xcode 5 new bug

    - by user2874675
    Since the recent IOS update last month I have been having issues with this new bug that has hampered my program. The bug is as follows: using a UIButton and I want to insert a value into it, only after my execution ends does a letter actually appear. But if I create a method during execution to tell me, using NSLog, what my properties contain then that letter I added never shows up. I'm thinking I need to find a way to refresh a property during execution instead in the end. For example: Let's say you want to insert the letter F into a UIButton. Immediately after writing F into that UIButton, look to see that F hasn't isn't in there. But it will only show up after that particular execution sequence finishes. Any help would be great. Thanks in advance.

    Read the article

  • Stata output files in surveys

    - by William Shakespeare
    I have some survey data which I'm using Stata to analyze. I want to compute means of one variable by group and save those means to a Stata file. My code looks like this: svyset [iw=wtsupp], sdrweight(repwtp1-repwtp160) vce(sdr) svy: mean x I tried svy: by grp: mean x but that did not work. I could save each mean to a separate file by simply saying svy: mean x if grp==1 but that's inefficient. Is there a better way? Saving results to a file like one can use SAS ODS to capture results is also a need. I am not talking about the log here. I need the means and the associated group. I'm thinking estimates save [path],replace but I'm not sure if that will give me a Stata file or the group if I can figure out how to use by processing.

    Read the article

  • PHPUnit Command Line Include Path

    - by thatidiotguy
    So I have a project structure like so: MyProject/ src/ //subfolders and source code ..... tests/ package/ MyTest.php I am trying to run the unit tests in MyTest.php with PHPUnit but it has a use statement for PHP classes located in the src folder. So I tried to use the include-path directive for PHPUnit like so: (I am in the directory with MyTest.php) phpunit --include-path ~/workspace/MyProject/src/ MyTest Unfortunately execution is halting at the first use statement. What gives?

    Read the article

  • Why is numpy's einsum faster than numpy's built in functions?

    - by Ophion
    Lets start with three arrays of dtype=np.double. Timings are performed on a intel CPU using numpy 1.7.1 compiled with icc and linked to intel's mkl. A AMD cpu with numpy 1.6.1 compiled with gcc without mkl was also used to verify the timings. Please note the timings scale nearly linearly with system size and are not due to the small overhead incurred in the numpy functions if statements these difference will show up in microseconds not milliseconds: arr_1D=np.arange(500,dtype=np.double) large_arr_1D=np.arange(100000,dtype=np.double) arr_2D=np.arange(500**2,dtype=np.double).reshape(500,500) arr_3D=np.arange(500**3,dtype=np.double).reshape(500,500,500) First lets look at the np.sum function: np.all(np.sum(arr_3D)==np.einsum('ijk->',arr_3D)) True %timeit np.sum(arr_3D) 10 loops, best of 3: 142 ms per loop %timeit np.einsum('ijk->', arr_3D) 10 loops, best of 3: 70.2 ms per loop Powers: np.allclose(arr_3D*arr_3D*arr_3D,np.einsum('ijk,ijk,ijk->ijk',arr_3D,arr_3D,arr_3D)) True %timeit arr_3D*arr_3D*arr_3D 1 loops, best of 3: 1.32 s per loop %timeit np.einsum('ijk,ijk,ijk->ijk', arr_3D, arr_3D, arr_3D) 1 loops, best of 3: 694 ms per loop Outer product: np.all(np.outer(arr_1D,arr_1D)==np.einsum('i,k->ik',arr_1D,arr_1D)) True %timeit np.outer(arr_1D, arr_1D) 1000 loops, best of 3: 411 us per loop %timeit np.einsum('i,k->ik', arr_1D, arr_1D) 1000 loops, best of 3: 245 us per loop All of the above are twice as fast with np.einsum. These should be apples to apples comparisons as everything is specifically of dtype=np.double. I would expect the speed up in an operation like this: np.allclose(np.sum(arr_2D*arr_3D),np.einsum('ij,oij->',arr_2D,arr_3D)) True %timeit np.sum(arr_2D*arr_3D) 1 loops, best of 3: 813 ms per loop %timeit np.einsum('ij,oij->', arr_2D, arr_3D) 10 loops, best of 3: 85.1 ms per loop Einsum seems to be at least twice as fast for np.inner, np.outer, np.kron, and np.sum regardless of axes selection. The primary exception being np.dot as it calls DGEMM from a BLAS library. So why is np.einsum faster that other numpy functions that are equivalent? The DGEMM case for completeness: np.allclose(np.dot(arr_2D,arr_2D),np.einsum('ij,jk',arr_2D,arr_2D)) True %timeit np.einsum('ij,jk',arr_2D,arr_2D) 10 loops, best of 3: 56.1 ms per loop %timeit np.dot(arr_2D,arr_2D) 100 loops, best of 3: 5.17 ms per loop The leading theory is from @sebergs comment that np.einsum can make use of SSE2, but numpy's ufuncs will not until numpy 1.8 (see the change log). I believe this is the correct answer, but have not been able to confirm it. Some limited proof can be found by changing the dtype of input array and observing speed difference and the fact that not everyone observes the same trends in timings.

    Read the article

  • Rails 3 and Bootstrap 2.1.0 - can't fix my footer

    - by ExiRe
    I have Rails application with bootstrap 2.1.0 (i use twitter-bootstrap-rails gem for that). But i can't get working footer. It is not visible unless i scroll down the page. I can't get how to fix that. Application.html.haml !!! %html %head %title MyApp = stylesheet_link_tag "application", :media => "all" = javascript_include_tag "application" = csrf_meta_tags %meta{ :name => "viewport", :content => "width=device-width, initial-scale=1.0" } %body %div{ :class => "wrapper" } = render 'layouts/navbar_template' %div{ :class => "container-fluid" } - flash.each do |key, value| = content_tag( :div, value, :class => "alert alert-#{key}" ) %div{ :class => "row-fluid" } %div{:class => "span10"} =yield %div{:class => "span2"} %h2 Test sidebar %footer{ :class => "footer" } = debug(params) if Rails.env.development? bootstrap_and_overrides.css.less @import "twitter/bootstrap/bootstrap"; body { padding-top: 60px; } @import "twitter/bootstrap/responsive"; // Set the correct sprite paths @iconSpritePath: asset-path('twitter/bootstrap/glyphicons-halflings.png'); @iconWhiteSpritePath: asset-path('twitter/bootstrap/glyphicons-halflings-white.png'); // Set the Font Awesome (Font Awesome is default. You can disable by commenting below lines) // Note: If you use asset_path() here, your compiled boostrap_and_overrides.css will not // have the proper paths. So for now we use the absolute path. @fontAwesomeEotPath: '/assets/fontawesome-webfont.eot'; @fontAwesomeWoffPath: '/assets/fontawesome-webfont.woff'; @fontAwesomeTtfPath: '/assets/fontawesome-webfont.ttf'; @fontAwesomeSvgPath: '/assets/fontawesome-webfont.svg'; // Font Awesome @import "fontawesome"; // Your custom LESS stylesheets goes here // // Since bootstrap was imported above you have access to its mixins which // you may use and inherit here // // If you'd like to override bootstrap's own variables, you can do so here as well // See http://twitter.github.com/bootstrap/less.html for their names and documentation // // Example: // @linkColor: #ff0000; //MY CSS IS HERE. html, body { height: 100%; } footer { color: #666; background: #F5F5F5; padding: 17px 0 18px 0; border-top: 1px solid #000; } footer a { color: #999; } footer a:hover { color: #efefef; } .wrapper { min-height: 100%; height: auto !important; height: 10px; margin-bottom: -10px; }

    Read the article

  • android - pre-allocate space for a file before downloading it

    - by android developer
    how can i create a pre-allocated file on android? something like a sparse file ? i need to make an applicaton that will download a large file , and i want to avoid having an out-of-space error while the download is commencing . my solution needs to support resuming and writing to both internal and external storage. i've tried what is written here: Create file with given size in Java but none of the solutions there didn't work for some reason.

    Read the article

< Previous Page | 7 8 9 10 11 12 13 14 15  | Next Page >