w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
When making binary masks for working and isolating bits and bytes, what's the fastest way to convert from Binary to Hex?
Each set of four bits corresponds to one hex 'digit'. Learn those, then just start converting blocks of four from right to left. (If you're converting a bit string that's not a multiple of four bits, then just add zeros to the left end until it is for the last conversion.) 0000 : 0x0 0001 : 0x1 0010 : 0x2 0011 : 0x3 0100 : 0x4 0101 : 0x5 0110 : 0x6 0111 : 0x7 1000 : 0x8 1001 : 0x9 1010 : 0xA 1011 : 0xB 1100 : 0xC 1101 : 0xD 1110 : 0xE 1111 : 0xF

Categories : C

How to find the closest element to a given binary key value using binary search algorithm?
In case you define the closest as the distance between two vectors. here is the pesudo code to to find the vector that is closest. Vector closestVector = null; Vector findClosestVector(L,q) { int i= L.lenght/2; if(i ==1 ) { Vector v = L.get(0); int distance = distance(v,q); if(closestVector == null) { closestVector = v; } else { int d1 = distance(closestVector,q); if(d1 > distance) { closestVector = v; return v; } } } else { Vector left = findClosestVector(L(0,L/2),q); Vector right = findClosestVector(L(L/2,L),q); if(distance(left,q) >

Categories : Java

Implementing a binary insertion sort using binary search in Java
How an insertion sort works is, it creates a new empty array B and, for each element in the unsorted array A, it binary searches into the section of B that has been built so far (From left to right), shifts all elements to the right of the location in B it choose one right and inserts the element in. So you are building up an at-all-times sorted array in B until it is the full size of B and contains everything in A. Two things: One, the binary search should be able to take an int startOfArray and an int endOfArray, and it will only binary search between those two points. This allows you to make it consider only the part of array B that is actually the sorted array. Two, before inserting, you must move all elements one to the right before inserting into the gap you've made.

Categories : Java

xor 2 binary strings and give result in binary using java
It sounds to me like homework or an assignment, so I'll offer guidance rather than code: Create an empty StringBuilder Iterate through these strings using a for loop with an index i Use charAt(i) to grab the character at position i If both characters are the equivalent at that position, append 0 to the string builder, otherwise append 1 to it When you're done iterating, return that string builder

Categories : Java

Binary to Text and just reverse it to binary using JAVA
If your file really contains binary (as in, not character data), then the way you are reading it in is almost guaranteed to lose data. You are transforming binary to a string using the default charset. On many systems, the default charset is UTF-8. Many binary sequences do not map to a valid unicode character, in those cases if you are interpreting that data as UTF-8, the default behavior is to replace that data with a set replacement character. That means you're going to lose a lot of data. If you really want to read in binary data as a String (which may well not be a good approach), use a charset which has a mapping for every possible bit sequence (such as Windows-1252) so that you can be sure you won't lose any data.

Categories : Java

Convert binary string to binary literal
The string is a literal. 3>> bin(int('0b1010', 2)) '0b1010' 3>> bin(int('1010', 2)) '0b1010' 3>> 0b1010 10 3>> int('0b1010', 2) 10

Categories : Python

How to deal with binary data in php (not binary string)?
You can use unpack: $num = unpack('n', $data); Use an uppercase letter for an unsigned integer, and a v (or V) for little-endian. Yes, you have to worry about endianness. Just find out what it is and stick with it.

Categories : PHP

MinGW binary 3x as big as MSVC binary
First off, who cares? Have you seen this larger size to impact performance? Second: are you sure you're linking statically with MSVC? Check with Dependency Walker to be sure. Third: yes MinGW GCC compiled binaries are generally larger. This is because MinGW provides a part of the C library to make up for how ridiculously broken msvcr* is compliance-wise. This has never shown as a large difference for me though. Fourth: template and inline handling can differ between the two compilers. Fifth: have you tried to compile the GCC version with -fno-keep-inline-dllexport and/or -Os?

Categories : Visual C++

Python: how to sum binaries? From binary-power-vector presentation to real binary presentation, how?
The value returned by the bin built-in is a simple string. It's not a "binary number". Binary numbers do not exist, there is only a binary representation of numbers. Python integers are internally represented as base-2, the bin function allow to "see" this(actually the modulus and sign representation, not two's complement) representation as a string. If you want to perform bitwise operations such as | on those strings you must convert them to integers and then back to strings: In [7]: bin(int('0b10000', 2)|int('0b100', 2)) Out[7]: '0b10100' If, given a list of binary strings, you want to obtain a number that combines those strings you can use the reduce function: In [8]: import operator as op In [9]: from functools import reduce In [10]: a = ['0b10000000000000000000000000', '0b1000

Categories : Python

Getting Cocoa function from C++
This answers the question and is worth the bounty The solution is to import NSUserName in C++ by using dlopen and dlsym: void* (*NSUserName)(); String UserName; void *hLib = dlopen("/System/Library/Frameworks/Foundation.framework/Foundation", RTLD_GLOBAL); if(hLib) { NSUserName = (void*(*)())dlsym(hLib, "NSUserName"); CFStringRef srUserName = (CFStringRef)NSUserName(); if(srUserName) { UserName = CFStringGetCStringPtr(srUserName, 0); } dlclose(hLib); } It is possible to use NSString (Cocoa Type) directly in C++ Builder by adding a header file as: #include <Macapi.Foundation.hpp> // note that this will cause 8080 warnings if you have this warning turned on (unused variables) Now I can use NSString instead CFStringRef (Core Foundation Type): Us

Categories : C++

Command-Key-Up Cocoa
According to the docs: Informs the receiver that the user has pressed or released a modifier key (Shift, Control, and so on). What you need to do here is when you get the event in which the command key goes down, you need to set a flag somewhere, and in subsequent calls, check for the absence of the command key being down. For instance, assuming you have an ivar called _cmdKeyDown: - (void)flagsChanged:(NSEvent *)theEvent { [super flagsChanged:theEvent]; NSUInteger f = [theEvent modifierFlags]; BOOL isDown = !!(f & NSCommandKeyMask); if (isDown != _cmdKeyDown) { NSLog(@"State changed. Cmd Key is: %@", isDown ? @"Down" : @"Up"); _cmdKeyDown = isDown; } }

Categories : Objective C

Cocoa OS X - App Installer
Take a look at PackageMaker. You can find it in 'Auxiliary Tools for Xcode' on apple downloads page. There are lot of tutorials in internet. There also was a doc on apple site, but I can't find it right now. You can also use packagemaker in terminal (thats how I create packages). Also take a look at this question. You can find some interesting info there.

Categories : Osx

Using MongoDB in a Cocoa app
If you want something like MongoDB running on the client side, I'ld recommend you to use ejdb instead. It's specifically built for that purpose. It aims to be a fast MongoDB-like library which can be embedded into C/C++/NodeJS/Python/Lua/Java/Ruby applications under terms of LGPL license.

Categories : Objective C

JavaScript: Need functions to convert a string containing binary to hex, then convert back to binary
Try this jsfiddle. The more interesting functions to you are here. Not necessarily the cleanest or most efficient ones, but yea: // converts binary string to a hexadecimal string // returns an object with key 'valid' to a boolean value, indicating // if the string is a valid binary string. // If 'valid' is true, the converted hex string can be obtained by // the 'result' key of the returned object function binaryToHex(s) { var i, k, part, accum, ret = ''; for (i = s.length-1; i >= 3; i -= 4) { // extract out in substrings of 4 and convert to hex part = s.substr(i+1-4, 4); accum = 0; for (k = 0; k < 4; k += 1) { if (part[k] !== '0' && part[k] !== '1') { // invalid character return { valid: fa

Categories : Javascript

Difference between dataType binary(1632) in SQL Server and dataType binary(255) in MYSQL?
Obviously, this has to do with the maximum size of the data the field is able to contain. If you really need the column be able to contain 1632 bytes of data, use the BLOB MySQL type instead.

Categories : C#

Get value of NSTextfield by tag number in Cocoa
Let's say the tag is 7. [contentView viewWithTag:7] That returns the tag, if a subview (including the view itself, contentView in this case) has this tag or nil if none is found. You are in charge with making sure to have the tags unique. For that you should never ever use 0 as tag value because 0 is the default value [contentView viewWithTag:0] would return contentView unless you set its tag to something else.

Categories : Objective C

How is this Cocoa window architected?
How are these designed? They're almost certainly using NSToolbar, a Cocoa class that makes it easy to add a number of icons, buttons, search bars, etc. to the top of a window such that the items look like part of the window title bar. It's impossible to know what they're using just by looking at them, but NSToolbar is one way to get that effect. Here's a good example straight from the linked documentation:

Categories : Xcode

How to use Faroo search API in cocoa
One other way of doing things is to declare the missing method yourself as a category of the class in question. This will get the compiler to stop complaining about not finding the method, though of course you'll still need the runtime check you're already doing to avoid actually calling the method. You might also want to wrap such a declaration using availability macros, so that it will be ignored once you do move up to using the 10.5/10.6 SDK and you won't get a different compiler complaint down the line. That would look something like this: #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_4 //ignore when compiling with the 10.5 SDK or higher @interface NSPropertyListSerialization(MissingMethods) + (NSData *)dataWithPropertyList:(id)plist format:(NSPropertyListFormat)format op

Categories : Objective C

Cocoa contents of directory
Lets just take 1 of your 3: [[NSFileManager defaultManager] contentsOfDirectoryAtPath:@"directoryName" error:nil] You should include the error parameter and check what it contains You need to supply a full path, not just a "directoryName" As a result you'll get an array containing the file names of the files in the directory So if you want the full path you can do: NSString *directoryPath = ...; NSArray *fileNames = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:directoryPath error:...]; for(NSString *fileName in fileNames) { NSLog(@"%@", [directoryPath stringByAppendingPathComponent:fileName]); }

Categories : Objective C

ImageMagick + Cocoa app in one bundle
I think that what you're looking for are instructions for building a static library for OS X? http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=13145&p=44175&hilit=static+Mac#p44175 Given that we don't know anything about your wrapper, it is hard to give advice beyond this.

Categories : Objective C

Is there any way to get the application's run time in Cocoa for OS X?
The easiest way to get an approximation of your application's running time would be to store a NSDate when the app delegate method applicationDidFinishLaunching: is called and subtract that date from the current time whenever you need the process running time. static NSTimeInterval startTime; - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { startTime = [NSDate timeIntervalSinceReferenceDate]; } - (IBAction)printRunningTime:(id)sender { NSLog(@"Approximate running interval:%f", [NSDate timeIntervalSinceReferenceDate] - startTime); } If you need a more accurate running interval for your PID, you can use sysctl. This will give you an exact timestamp for the point where the OS considers your process "running" in UNIX time. (If you want the timestamp in your l

Categories : Osx

Cocoa frameworks that don't need to be #imported
Look for yourProjectName-Prefix.pch file. There you'll find: #ifdef __OBJC__ #import <UIKit/UIKit.h> #import <Foundation/Foundation.h> #endif Inside the #ifdef statement you can add any files you like that will automatically imported throughout you whole project.

Categories : Objective C

Object under mouseDown COCOA
In your view mouseDown method, you can call the hitTest: method to get the farthest descendant of the receiver in the view hierarchy that was clicked: So in your view subclass, you could do something like: - (void)mouseDown:(NSEvent *)theEvent { id clickedObject = [self hitTest:[theEvent locationInWindow]]; if ([clickedObject isKindOfClass:[NSImageView class]]) { NSLog(@"Clicked an ImageView"); } else if ([clickedObject isKindOfClass:[WebView class]]) { NSLog(@"Clicked a WebView"); } } Your question seems a bit odd though, because normally you don't need to do this hit testing yourself. If you're trying to get a click event when a particular image is clicked, a better way would be to use a borderless button with an image set and then implementing an a

Categories : Objective C

How to use Reactive Cocoa with notifications
In the RACExtensions you can find the NSNotificationCenter (RACSupport) category. That has a method for this purpose: - (RACSignal *)rac_addObserverForName:(NSString *)notificationName object:(id)object;

Categories : IOS

Create OS X window without Cocoa
I haven't much detail to give you, but I may be able to point you in a direction. There is one level down, which is Quartz Window Services. That's what both NSWindow and Carbon's Window Manager are based on. It peeks through occasionally, even in the public API. You can ask any window for its window number (and likewise in Carbon), and with that, you can use anything in the public Quartz Window Services API. That doesn't get you very far, though: There's not much you can do with that besides take screenshots. If you were to create a window with Quartz, though, it would (probably—I've never tried this) be blank. The title bar and background are drawn separately. To do that, NSWindow has a second view ivar for a view called the frame view, which presumably uses HITheme. (Surprising amo

Categories : Osx

OpenGL and Cocoa not Working
Where is your view matrix (AKA your look-at matrix)? For my NSOpenGLView, I have at least three matrices, the model view (which consists of the multiplicative result of the rotation and translation matrices), the projection matrix (which takes into account your frustum scale, aspect ratio, near plane, and far plane), and the view matrix (which takes into account the viewers eye position in the "world", the point of focus, and the direction of the up vector). I will say big ups on placing the code in the awakeFromNib, taught me something...

Categories : Osx

Adding a new window in Cocoa
You mostly only create a new NSWindowController if you add a new Nib-File. The advantage of separating your windows or separate views in Nib-Files can be: Making your code more organized Easy instantiation of multiple windows of the same type (like browser windows) If you don't need this, you can simply add a new window to your MainMenu.xib. Then you can either let the window be visible at launch, or make an outlet to it and make it visible whenever you desire. Otherwise you can go to your files -> Add new file -> Subclass of NSWindowController There will be a checkbox to automatically create the xib-file for you, make sure to check. Now just make sure to initialise with initWithWindowNibName:, and call showWindow: on it. MyWindowControllerSubclass *wcs = [[MyWindowControllerSubc

Categories : Objective C

How to replace first byte in cocoa
"NSMutableData" has a very handy function "replaceBytesInRange: withBytes:" that you can use to replace things. So modify your code to look something like this: NSMutableData *data = [NSMutableData dataWithContentsOfFile:@"test"]; NSLog(@"Patch File: %@",data); int value; [data getBytes: &value range: NSMakeRange(0,1)]; NSLog(@"%d",value); if( value == 49) value = 48; [data replaceBytesInRange: NSMakeRange(0,1) withBytes: &value]; NSLog(@"%d",value); NSError * error = nil; BOOL success = [data writeToFile: @"file" options: NSDataWritingAtomic error: &error]; if(success == NO) { NSLog( @"error writing data out -- %@", [error localizedDescription]); }

Categories : Objective C

how to deploy database file in cocoa app
You cannot update the app bundle, so you must copy the empty database to a user directory upon first run. If you are hoping to publish this app to the Mac App Store then it must be sandboxed which means that the only place you can put the database is in the app container folder. You can obtain the app container folder using NSHomeDirectory(), which will work whether you sandbox the app or not.

Categories : Osx

How does the cocoa "view" system work?
Your desire to make the main view(s) independent of the menu, window, etc. is a good one. There's no one single way to do this of course, but the way I would do it is to have the window controller be the object that handles taking input from the menu and switching the main view area to the correct view. To actually handle switching views, I'd use an NSTabView which is made for exactly this purpose. You can set it up in Interface Builder so that it doesn't actually draw tabs, is 'invisible' to the user, and just switch tabs programatically. The one hangup with a tab view is that it's not intrinsically designed to switch between multiple view controllers' views (NSViewController being a relatively new class in the history of Cocoa). So, you'll have to have the window controller keep (stron

Categories : Xcode

How to clear all object on NSView in Cocoa
You can make something like this: // TSClearSupporting.h @protocol TSClearSupporting <NSObject> - (void) clear; @end // TSTextField.h #import <Cocoa/Cocoa.h> #import "TSClearSupporting.h" @interface TSTextField : NSTextField <TSClearSupporting> @end // TSTextField.m #import "TSTextField.h" @implementation TSTextField - (void) clear { self.stringValue = @""; } @end // TSMainView.m #import "TSMainView.h" #import "TSClearSupporting.h" @implementation TSMainView - (IBAction) clearAll: (id)sender { NSArray* subViews = self.subviews; for (NSView* view in subViews) { if ([view conformsToProtocol: @protocol(TSClearSupporting)]) { [view performSelector: @selector(clear)]; } } }

Categories : Objective C

python and Cocoa: about statusbar script
All of your problems come from the fact that you're blocking the main thread. In Cocoa, or almost any other GUI framework, the main thread runs a loop that waits for the next event, calls an event handler, and repeats until quit. Your event handler, applicationDidFinishLaunching_, never returns. This means Cocoa can never handle the next event. Eventually, the OS will notice that you're not responding and put up the beachball. With Cocoa, sometimes it sneaks in some other events each time you give it a chance, like on the setTitle_ calls, and there are some things the OS can fake even if you're not responding, like keeping the window redrawing, so it isn't always obvious that your app is not responsive. But that doesn't mean you don't need to solve the problem. There are a number ways

Categories : Python

Cocoa touch - Error getting JSON key
If you inspect your json you'll see that screen_cap_url_medium is under channel object, so you can access it like this: [dictionary valueForKeyPath:@"channel.screen_cap_url_medium"]; PS. Here dictionary is obviously the first object of the root array you get back from your response.

Categories : Json

Cocoa Pods import issue
The ShareKit podspec uses subspecs which allows the maintainers to separate the parts of the larger libraries into separate includes so you don't have to have parts you don't need. For example in the ShareKit spec they separate services s.subspec 'Evernote' do |evernote| evernote.source_files = 'Classes/ShareKit/Sharers/Services/Evernote/**/*.{h,m}' evernote.dependency 'Evernote-SDK-iOS', "~> 1.2" evernote.dependency 'ShareKit/Core' end s.subspec 'Facebook' do |facebook| facebook.source_files = 'Classes/ShareKit/Sharers/Services/Facebook/**/*.{h,m}' facebook.dependency 'Facebook-iOS-SDK',"~> 3.5" facebook.dependency 'ShareKit/Core' end So if you only wanted support for Evernote you wouldn't also have to include Facebook. This means in your Podfile you have to specif

Categories : IOS

How to install VTK 6.1 for OSX 10.8 with Cocoa/XCode support?
* Installing VTK 6.1 for OSX 10.8 with Cocoa support * These instructions slightly modify Ryan Glover's instructions at http://www.vtk.org/Wiki/Cocoa_VTK and the README.rtf in the VTK/Examples/GUI/Cocoa/Documentation folder by Sean McBride and Mike Jackson. Clone the VTK git repo into a directory of your choice: cd /Users/you/ git clone https://github.com/Kitware/VTK.git cd VTK git checkout tags/v6.1.0 make a build directory mkdir VTKBuild cd VTKBuild Run the VTK cmake script You will now be inside /Users/you/VTK/VTKBuild, run cmake from here (using the parent directory's CMake files): cmake .. Edit lots of lines in the newly generated CMakeCache.txt (in the current VTKBuild directory). One issue I had was that there were error if I didn't use a ful

Categories : Osx

Cocoa Pods and Google Maps SDK
You should not have to import anything linked with CocoaPods using < and >. It should simply be #import "Foo.h". In the case of Google Maps based on my test project I just had to use #import "GoogleMaps.h" and it imported correctly. Make sure you're installing with the newest version of CocoaPods (pod --version currently 0.21.0) otherwise you may need to update it ([sudo] gem update). Also make sure you're opening the created xcworkspace file instead of the xcodeproject

Categories : Misc

How to add an action event to Tooltip in cocoa
//tooltip is your NSStatusItem [tooltip setAction:@selector(tooltipClicked:)]; This calls method tooltipClicked when clicked: - (void)tooltipClicked:(id)sender { ... }

Categories : Objective C

How to detect right and left click in cocoa
You have to override NSResponder methods like: - (void) mouseDown: (NSEvent*) theEvent; - (void) rightMouseDown (NSEvent*) theEvent; Reference: NSResponder Documentation.

Categories : Objective C

Cocoa Object Idle Timer
You could use a delegate pattern. 1) Make a protocol JoystickDelegate, declare the method - (void)joystickInvalidated:(Joystick *)joystick. 2) JoystickController should then implement JoystickDelegate. Implement the method to remove joystick from your array. 3) Finally make a weak property called delegate in the Joystick interface and on every init of Joystick in joystickAdded assign self on js.delegate. 4) Now whenever invalidate is called, just call the delegate with self inside Joystick: [self.delegate joystickInvalidated:self];

Categories : Objective C

A way to schedule a method call in Cocoa?
performSelector:withObject:afterDelay can be used for this. The delay is relative so you need to compute the difference between your desired date and the current time. Something like this (typed directly into answer on an iPad - E&OE): - (void) fooWithObject:(MyObject *)obj onDate:(NSDate *)onDate { [self performSelector:@selector(fooWithObject:) withObject:obj afterDelay:MAX(0, [onDate timeIntervalSinceNow]) ]; } Note that MAX is used in case the passed in date is in the past - the delay will be 0 and the selector will therefore be performed "as soon as possible".

Categories : Osx



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.