AppleTV and CommonJS or AMD (require.js) - module

Is there anyone who successfully used either require.js or one of the commonJS implementations in apple tv apps? I wanted to give a try to require.js, but spotted right away that require.js uses window object and maybe some other stuff that simply doesn't exist on apple tv. So maybe I should look for other options? How do you guys deal with modules? My predecessor just concatenated bunch of .js files and made a mess with literally tens of thousands lines of code. Incredibly messy.
upd: Still trying to make require.js work but apple tv won't let me have data-main attribute in script tag, I guess you can run require.config in the next script that loads right after
upd2: Doesn't work... apple tv doesn't have window object... Darn you Apple... I'll try to make changes to require.js file itself
No... definitely require.js not suited, even after major refactoring and changing browser specific stuff in the lib to ATV specific, still doesn't work. :(

Related

How to make Bootstrap 3 and Ant Design 3 live together

We are working on a React application (using Create React App without ejecting it) and we decided to use Ant as our base component library.
Now that we are near the end of the project, we discover that the application will be integrated into a corporate portal (WebSphere) as a "portlet", so we inherit all the CSS files from the main page.
Both frameworks seem to have their own reset styles, but they use different values.
So far, I have not been able to find a LESS variable in Ant that can be used for prefix all Ant's CSS rules.
Has anyone ever tried to make them live together?
We don't own the parent development, we can only make change on the React part, so only things related to Ant.
We finally go with a specific CSS patch file, and we add rules when needed.
Not really perfect, but none of the suggested path did the job we expected.
Here you can see some of the default antd variables.
One of them is #ant-prefix: ant;. I think you can change it and apply different styles.
That is a tough one, and at the end of development no less!
As #froston mentions, and which you seem to have tried the #ant-prefix: ant; in addition to this you will need to se prefixCls as a prop on every component instance you create, which will definitely be an exercise in self-flagellation.
Even if you set a global CONSTANT and import and use this with your components, you still have to thread it through to all the places, and will need to be appended with the component name.
By way of example, the defaultProps for an anchor is prefixCls: 'ant-anchor'.
Hope this helps and good luck!

How to automatically reload Clojure code?

How to automatically reload Clojure code?
I have watched the presentation. And in there they use some hot swap Clojure technology that reloads code whenever changes are made into source files. I can run the code, but I can not observe the effect of auto reload. How is it possible to reload the code?
the source code.
There are many ways to reload code, depending on the situation:
Emacs/CIDER shortcuts to reload a file. Probably Rich is doing something similar. Also see this: How to reload a clojure file in REPL
watch files and reload the code (figwheel for frontend development does that, test plugins as well as CIDER shortcuts specifically for running tests, boot has a watch task...)
a middleware for the web server you use (ring for example has ring.middleware.reload/wrap-reload for this, pedestal comes with one as well, other webservers like yada play well with component)
a component workflow works also, there is an example of an auto-reloadable system with holy-grail
(I didn't fully re-watch this video, but these notes are from my observations after skipping through the video and making educated guesses)
From what I re-watched of this video it looks like Rich is evaluating the code in a running repl. This allows him to change the code, evaluate it, and see different behavior.
Many editors have support for evaluating code in a buffer in a Clojure repl. Here is some documentation on using CIDER with Emacs to get to interactively play with your code.
Unrelated to the video in question, if you are using ring for web development. You can use the wrap-reload middleware to have your code automatically reloaded when a file has changed and a request hits your web app. This is extremely useful when developing a Clojure web application.
For automatically reloading and running your clojure.tests I recommend lein-test-refresh. It is a Leiningen plug-in that monitors your project for file changes and when something changes it reloads and runs your tests. If you have tests for your project this greatly speeds up development.
Use mount to manage the starting and stopping of your components. For example in a backend web app, you'll want to startup the db before you start the webserver probably.
Then in emacs you can have:
(defun cider-repl-refresh ()
(interactive)
(save-some-buffers)
(with-current-buffer (cider-current-repl-buffer)
(goto-char (point-max))
(insert (concat "(require 'clojure.tools.namespace.repl) "
"(clojure.tools.namespace.repl/refresh)"))
(cider-repl-return)))
If you are not super fond of Emacs (I love Emacs, but hey not everybody does) LightTable is a very nice option for Clojure/ClojureScript interactive programming too.
For developing ClojureScript (Clojure that compiles to Javascript) LightTable and Figwheel are a really nice pair.
In my opinion LightTable has some advantages against Emacs (I never got cider to work perfectly with ClojureScript) for the webdev side, LightTable is basically a specialized version of Chrome, because it is built on top of Electron.
Check this documentation on the Figwheel GitHub page: Running Figwheel with LightTable:
If you are using Cursive IDE in IntelliJ, there is a special REPL tool which you have to setup to get the functionality you are looking for. It has many features vs. "lein repl" in a terminal window.
Full tutorial here: https://cursive-ide.com/userguide/repl.html
However, its very easy to setup a default instance:
Right click project.clj/deps.edn -> "Create Repl for...". Default settings are fine. Hit ok/apply.
Right click project.clj/deps.edn -> "Run Repl for..." (a repl window will open)
See Tools->Repl for a list of commands, such as:
switch to repl window: Ctrl+\
reload current file in repl: Alt + Shift + L
send function defn to repl: Alt + Shift + M
... and more
In addition you'll get full code completion, syntax highlighting, etc. when writing in a REPL.

Automatic generation of HAML from HTML in SublimeText 2?

I would like to have SublimeText show the HTML result of parsing my HAML in another window, live, as I type the HAML.
Does anyone have an idea of how to make this happen? In, e.g., WebStorm there are file watchers that do this, but is there something like that built into ST2?
I did something similar to this with Typescript, only I only updated the Javascript output when I saved the file. First, I would say to take a look at SublimeBuildOnSave. That'll show you how to hook into the save function and see what file is being saved.
When you've got the general idea, you can take a look here and mess around with opening another pane (or using the existing pane) to show the compiled output.
It's pretty simple to make a simple version of this. If you want more advanced features like live compiling, it'll take a bit more effort, but it's not impossible. But the above scenario worked just fine for Typescript for me. (If I find where I left that code, I'll post it.)

JSLint, when using JS frameworks

I use the Dojo framework, which I load from an url.
How should I deal with the 'dojo' was used before it was defined errors, and the alike?
Yes, my feeling really get hurt, when running code through JSlint.
Perhaps you can put something like
/* globals dojo */
in the beggining of your file to tell JSLint that dojo exists?
I personaly use JSHint (a fork of JSLint that is less nitpicky) instead and one of the preconfigured options is support for Dojo.
Sounds like you need to put Dojo first in your JavaScript. The message suggests that you have an ordering problem.
Don't take it personally. You are not your code. Just make it better, learn something, and don't do it again.
If you scroll all the way down to the bottom there is a "predefined" textbox. Simply put in any of the variables you need into there (comma separated).

How to Write OS X Finder plugin

I'm looking for a guide or sample code for writing Mac OS X Finder plugins? It would like to know how to do some simple actions:
adding image overlayers to icons
adding context menu items
listen to file changes
I found the following two resources:
Writing Contextual Menu Plugins for OS X: An outdated document from 2002 that uses the COM API targeting Mac OS X 8/9.
SCPlugin: Open-source SVN Mac application that includes a Finder plug-in.
I am tempted to review the SCPlugin code, but was hoping to find an easier sample to digest.
The Finder Icon Overlay example project represents a small and very basic but actually working example of the answer below.
https://github.com/lesnie/Finder-Icon-Overlay
I know this is so old, but some may be still interested in topic (?)
Here is what I have it done under Leopard (10.6). At first proper Finder's headers are needed. Use class-dump tool to get it. Then write your code as a SIMBL plugin (refer to documentation how to do it), swizzling some methods. For instance to draw something over icon in ListView, drawIconWithFrame: method of TIconAndTextCell method must be overriden.
Here's the code for method swizzling:
+ (void) Plugin_load
{
Method old, new;
Class self_class = [self class];
Class finder_class = [objc_getClass("TIconAndTextCell") class];
class_addMethod(finder_class, #selector(FT_drawIconWithFrame:),
class_getMethodImplementation(self_class, #selector(FT_drawIconWithFrame:)),"v#:{CGRect={CGPoint=dd}{CGSize=dd}}");
old = class_getInstanceMethod(finder_class, #selector(drawIconWithFrame:));
new = class_getInstanceMethod(finder_class, #selector(FT_drawIconWithFrame:));
method_exchangeImplementations(old, new);
}
I am overriding "drawIconWithFrame:" method with my method "FT_drawIconWithFrame:". Below is sample implementation for this method.
- (void) FT_drawIconWithFrame:(struct CGRect)arg1
{
[self FT_drawIconWithFrame:arg1];
if ([self respondsToSelector:#selector(node)]) {
if ([[[[NSClassFromString(#"FINode") nodeWithFENode:[(TNodeIconAndNameCell *)self node]] fullPath] lastPathComponent] hasPrefix:#"A"])
[myPrettyIconOverlayImage drawInRect:NSMakeRect(arg1.origin.x, arg1.origin.y, arg1.size.height, arg1.size.height) fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
}
}
Essentially it draws "myPrettyIconOverlayImage" over every icon for file with filename starts with letter "A". This logic is up to you.
Pay attention to this line: [self FT_drawIconWithFrame:arg1]; this is how to call 'super' in order to get normal icon and name etc. I know, looks weird, like loop, but actually it isn't. Then wrap in into SIMBL plugin, install SIMBL and ...run.
Due to changes in Lion some work have to be done from scratch (make new "Finder.h" file with all declarations needed in it, find proper classess and methods to override), but this technique still works.
Happy hacking!
For Yosemite (MacOS 10.10 & newer), you can use Apple's FinderSync framework, which allows Finder extensions to:
Express interest in specific folder hierarchies
Provide "badges" to
indicate the status of items inside those hierarchies
Provide dynamic
menu items in Finder contextual menus, when the selected items (or
the window target) are in those hierarchies
Provide a Toolbar Item
that displays a menu with dynamic items (even if the selection is
unrelated)
Sadly, programming a Finder plugin actually does still require getting your hands dirty with COM. If you look at the SCFinderPlugin subproject of the SCPlugin project, you will find that it follows exactly the same techniques outlined in your first link, including setting up a vtable for COM, writing AddRef/ReleaseRef functions, and so on. Writing a plugin, where you're simultaneously managing old-school Carbon memory management, COM-style memory management, and Cocoa/new-style Carbon memory management, can be an incredible pain—and that totally ignores the fact that you'll be interacting in three or more radically different APIs, with different naming conventions and calling semantics. Calling the situation hysterically poor would be a vast understatement.
On the bright side, the Finder in Mac OS X 10.6 Snow Leopard has been fully rewritten in Cocoa--and with that come vastly superior plugin interfaces. If you are lucky enough to be in a situation where you can actually only target Snow Leopard, you probably should grab an ADC Premier or higher membership, download the prerelease builds, and code against that. Besides, your plugin may not work on 10.6 anyway without a Cocoa rewrite, so it might make good sense to take a look at Snow Leopard before it gets released, regardless.
There is no official or supported plugin system for the Finder. Starting with OS X 10.6, you will need to inject code into the Finder process and override objective C methods in the Finder process.
I've done this for a proprietary project. I can tell you that the reason that there are no examples or tutorials for this is because it is a significantly difficult and time consuming development task. For this reason, there's plenty of incentive for individuals or organizations who have accomplished this to guard the specifics of their process closely.
If there's any way at all that you can accomplish your goal using the Services API, do it. Writing a Finder plugin will take you 1-2 solid months of painstaking development and reasonably deep knowledge of C and Objective-C internals.
If you're still convinced that you want do to this, grab mach_star. Good luck.
As far as I know, there's no official plugin architecture for the Finder. You may be able to add image overlays to icons through an external application without having to hook into the Finder, although it wouldn't be on the fly. I don't think there is a way to add contextual menu items aside from Folder Actions and Automator. You can also look into writing an external application to monitor File System changes using the FSEvents API.
Here's a completed solution for Finder icon badges and contextual menus in Lion and Mountain Lion using the techniques described by Les Nie.
Liferay Nativity provides a scripting bundle that will swizzle the relevant Finder methods and a Java client for setting the icons and context menus. It also includes equivalent projects for Windows and Linux.
The project is open source under LGPL, so feel free to contribute any bug fixes or improvements!
The pickings are slim; it's never been really clear to me whether Finder Plugins are actually supported. A few more leads, though:
SampleCMPlugIn - Carbon-based of course, since so is Finder. Note that almost any Finder plugin is probably going to stop working with 10.6.
Automator can save things as a "Finder plugin." It's a more supported version of what you're discussing, but of course less flexible.
To add Finder/File browser icon overlays and context menus, in a cross-platform manner, from Java, take a look at the Liferay Nativity library.
I also make mention of this in another SO post, which also contains links to Apple's 'Finder Sync' docs and API.