I'm trying to get started playing with factor.
So far, I've:
downloaded the OSX disk image
copied the factor directory into $INSTALL/factor
started up the debugger by running $INSTALL/factor/factor
Which seems to be running great.
Following the instructions for writing your first factor program, I noticed that scaffold-vocab generated files in my $INSTALL/factor/work directory. Which I can use for now, but in general, I like to keep a separate $INSTALL directory-tree and $CODE directory-tree.
So I'm trying to follow the instructions from the "Working with code outside of the Factor directory tree" documentation to add other directories to the path used to load code into the factor executable, but I'm not having much luck.
First, I tried to set a FACTOR_ROOTS environment variable:
% export FACTOR_ROOTS=.:$CODE/Factor:$INSTALL/factor
% $INSTALL/factor/factor
( scratchpad ) "work" resource-path .
"/usr/local/src/factor/work"
( scratchpad ) ^D
Then, I tried to create a ~/.factor-roots file
% echo . > ~/.factor-roots
% echo $CODE/Factor >> ~/.factor-roots
% echo $INSTALL/factor >> ~/.factor-roots
% $INSTALL/factor/factor
( scratchpad ) "work" resource-path .
"/usr/local/src/factor/work"
( scratchpad ) ^D
Then I checked to see if it should be ./.factor-roots instead:
% mv ~/.factor-roots .
% $INSTALL/factor/factor
( scratchpad ) "work" resource-path .
"/usr/local/src/factor/work"
( scratchpad ) ^D
Lastly, I tried adding it manually:
% $INSTALL/factor/factor
( scratchpad ) "." add-vocab-root
( scratchpad ) "$CODE/Factor" add-vocab-root ! no, I didn't actually use an environment variable here :)
( scratchpad ) "work" resource-path .
"/usr/local/src/factor/work"
( scratchpad ) ^D
It seems I'm missing something fundamental here.
How do I write code outside of the $INSTALL/factor directory-tree and use it in factor? How can I tell scaffold-vocab to build scaffolding in my $CODE/Factor directory?
Ok, I was able to work out what I was doing wrong thanks to the earnest help of slava and erg on #concatenative.
Simply put, resource-path is not a way to test your factor roots. Like the docs say it "resolve[s] a path relative to the Factor source code location."
A more effective test is simply vocab-roots get, which will fetch the current list of vocab roots.
"/path/to/wherever" add-vocab-root will add /path/to/wherever to your list of vocab-roots, and allow you to do "/path/to/wherever" "project" scaffold-vocab so you can build scaffolding in the desired location.
As erg said:
i usually make another word, like
: scaffold-games ( vocab -- ) [ "/home/erg/games" ] dip scaffold-vocab ;
"minesweeper" scaffold-games
Related
I was wondering if it was possible to use the ReadFromText PTransform passing it multiple path.
My PTranform expand method is:
def expand(self, pcoll):
dataset = (
pcoll
| "Read Dataset from text file" >> beam.io.ReadFromText(self._source)
And source right now is a string with a path with a blob pattern
self._source="gs://bucket1/folder/*
From the documentation it says:
Args:
file_pattern (str): The file path to read from as a local file path or a
GCS ``gs://`` path. The path can contain glob characters
(``*``, ``?``, and ``[...]`` sets).
But even if it works greatly if I use gs://folder/*.gz (I have multiple files under a path) I can't seem to make it work if I have different path (or, in my case, in different buckets).
I tried with the command ls with something like:
gsutils ls gs://{bucket1/folder,bucket2/folder}/*
But if I try it with the beam pipeline it doesn't work and gives me
ERROR: (gcloud.dataflow.flex-template.run) unrecognized arguments:
Is there a way to make it work ?
As you explained in your comment, you can solve it with a for loop on the Beam Pipeline, example :
bucket_paths = [
"gs://bucket/folder/file*.txt",
"gs://bucket2/folder/file*.txt"
]
with beam.Pipeline(options=PipelineOptions()) as p:
for i, bucket_path in enumerate(bucket_paths):
(p
| f"Read Dataset from text file {i}" >> beam.io.ReadFromText(bucket_path)
....
)
I need a list of directory in LUA
Suppose I have a directory path as "C:\Program Files"
I need a list of all the folders in that particular path and how to search any particular folder in that list.
Example
Need a list of all the folder in path "C:\Program Files"
Below are folder name in the above path
test123
test4567
folder 123
folder 456
folder 456 789
Need to get the above in a list and then have to search for a particular string like folder 456 in folder 456 789 only.
Have Tried below code. Something I am missing below:-
local function Loc_Lines( str )
--
local ret= {} -- 0 lines
while str do
local _,_,line,tail= string.find( str, "(.-)\n(.+)" )
table.insert( ret, line or str )
str= tail
Print (str)
end
return ret
end
local function Loc_ShellCommand( cmd )
--
local str= nil
--
local f= io.popen( cmd ) -- no command still returns a handle :(
if f then
str= f:read'*a'
Print(str)
f:close()
end
if str=="" then -- take no output as a failure (we can't tell..)
Print("hi")
str= nil
end
-- Remove terminating linefeed, if any (eases up one-line analysis)
--
if str then
if string.sub( str, -1 ) == '\n' then
str= string.sub( str, 1, -2 )
end
end
return str
end
local function Loc_DirCmd( cmd )
Print(cmd)
local str= Loc_ShellCommand( cmd )
return Loc_Lines(str)
end
local function Loc_DirList( dirname )
local ret= {}
local lookup= {}
local tbl= Loc_DirCmd( "dir /AD /B "..dirname ) -- only dirs
-- Add slash to every dir line
--
for i,v in ipairs(tbl) do
table.insert( ret, v..'\\' )
lookup[v]= true
end
-- Return with forward slashes
--
if true then
for i=1,table.getn(ret) do
ret[i]= string.gsub( ret[i], '\\', '/' )
Print (ret[i])
end
end
return ret
end
Loc_DirList("C:\\Program Files\\")
I hate having to install libraries (especially those that want me to use installer packages to install them). If you're looking for a clean solution for a directory listing on an absolute path in Lua, look no further.
Building on the answer that sylvanaar provided, I created a function that returns an array of all the files for a given directory (absolute path required). This is my preferred implementation, as it works on all my machines.
-- Lua implementation of PHP scandir function
function scandir(directory)
local i, t, popen = 0, {}, io.popen
local pfile = popen('ls -a "'..directory..'"')
for filename in pfile:lines() do
i = i + 1
t[i] = filename
end
pfile:close()
return t
end
If you are using Windows, you'll need to have a bash client installed so that the 'ls' command will work - alternately, you can use the dir command that sylvanaar provided:
'dir "'..directory..'" /b /ad'
Take the easy way, install lfs. Then use the following constructs to find what you need:
require'lfs'
for file in lfs.dir[[C:\Program Files]] do
if lfs.attributes(file,"mode") == "file" then print("found file, "..file)
elseif lfs.attributes(file,"mode")== "directory" then print("found dir, "..file," containing:")
for l in lfs.dir("C:\\Program Files\\"..file) do
print("",l)
end
end
end
notice that a backslash equals [[\]] equals "\\", and that in windows / is also allowed if not used on the cmd itself (correct me if I'm wrong on this one).
for dir in io.popen([[dir "C:\Program Files\" /b /ad]]):lines() do print(dir) end
*For Windows
Outputs:
Adobe
Bitcasa
Bonjour
Business Objects
Common Files
DVD Maker
IIS
Internet Explorer
iPod
iTunes
Java
Microsoft Device Emulator
Microsoft Help Viewer
Microsoft IntelliPoint
Microsoft IntelliType Pro
Microsoft Office
Microsoft SDKs
Microsoft Security Client
Microsoft SQL Server
Microsoft SQL Server Compact Edition
Microsoft Sync Framework
Microsoft Synchronization Services
Microsoft Visual Studio 10.0
Microsoft Visual Studio 9.0
Microsoft.NET
MSBuild
...
Each time through the loop you are given a new folder name. I chose to print it as an example.
I don't like installing libraries either and am working on an embedded device with less memory power then a pc. I found out that using 'ls' command lead to an out of memory. So I created a function that uses 'find' to solve the problem.
This way it was possible to keep memory usage steady and loop all the 30k files.
function dirLookup(dir)
local p = io.popen('find "'..dir..'" -type f') --Open directory look for files, save data in p. By giving '-type f' as parameter, it returns all files.
for file in p:lines() do --Loop through all files
print(file)
end
end
IIRC, getting the directory listing isn't possible with stock Lua. You need to write some glue code yourself, or use LuaFileSystem. The latter is most likely the path of least resistance for you. A quick scan of the docs shows lfs.dir() which will provide you with an iterator you can use to get the directories you are looking for. At that point, you can then do your string comparison to get the specific directories you need.
You also install and use the 'paths' module. Then you can easily do this as follow:
require 'paths'
currentPath = paths.cwd() -- Current working directory
folderNames = {}
for folderName in paths.files(currentPath) do
if folderName:find('$') then
table.insert(folderNames, paths.concat(currentPath, folderName))
end
end
print (folderNames)
-- This will print all folder names
Optionally, you can also look for file names with a specific extension by replacing fileName:find('$') with fileName:find('txt' .. '$')
If you're running on a Unix-based machine you can get a numerically-sorted list of files using the following code:
thePath = '/home/Your_Directory'
local handle = assert(io.popen('ls -1v ' .. thePath))
local allFileNames = string.split(assert(handle:read('*a')), '\n')
print (allFileNames[1]) -- This will print the first file name
The second code also excludes files such as '.' and '..'. So it's good to go!
Don't parse ls, it's evil! Use find with zero-terminated strings instead (on linux):
function scandir(directory)
local i, t = 0, {}
local pfile = assert(io.popen(("find '%s' -maxdepth 1 -print0"):format(directory), 'r'))
local list = pfile:read('*a')
pfile:close()
for filename in s:gmatch('[^\0]+')
i = i + 1
t[i] = filename
end
return t
end
WARNING: however, as an acceped answer this apporach could be exploited if directory name contain ' in it. Only one safe solution is to use lfs or other special library.
Few fixes of val says Reinstate Monica solution:
function scandir(directory)
local pfile = assert(io.popen(("find '%s' -mindepth 1 -maxdepth 1 -type d -printf '%%f\\0'"):format(directory), 'r'))
local list = pfile:read('*a')
pfile:close()
local folders = {}
for filename in string.gmatch(list, '[^%z]+') do
table.insert(folders, filename)
end
return folders
end
Now it filters by folders, excludes dir itself and prints only names.
I am trying to use this script:
http://nsis.sourceforge.net/CheckSpaceFree
But it lacks some fundamental checks and adjustments ( comments ) for the case(s), where:
1) The $INSTDIR Path contains Program Files directory, which is Access protected, therefore, even if running setup with admin priviledges, you still get 0 integer return when, for example, your path ( absolute or relative ) lands on program files directory.
Failing Test path: C:\Program Files(x86)\BlaBlaBla\
Working test path: C:\BlaBlaBla
2) If I try to use relative path containing one level up (..\BlaBlaBla) AND point it to Disk root ( C:\ ), then path summerizes to C:\..\BlaBlaBla , resulting that nsis simply crashes.
Any best-pratice based way to gracefully work around these limitations?
Thank you all for any input!
Have you tried DriveSpace from the "useful headers" included with NSIS?
I need a list of directory in LUA
Suppose I have a directory path as "C:\Program Files"
I need a list of all the folders in that particular path and how to search any particular folder in that list.
Example
Need a list of all the folder in path "C:\Program Files"
Below are folder name in the above path
test123
test4567
folder 123
folder 456
folder 456 789
Need to get the above in a list and then have to search for a particular string like folder 456 in folder 456 789 only.
Have Tried below code. Something I am missing below:-
local function Loc_Lines( str )
--
local ret= {} -- 0 lines
while str do
local _,_,line,tail= string.find( str, "(.-)\n(.+)" )
table.insert( ret, line or str )
str= tail
Print (str)
end
return ret
end
local function Loc_ShellCommand( cmd )
--
local str= nil
--
local f= io.popen( cmd ) -- no command still returns a handle :(
if f then
str= f:read'*a'
Print(str)
f:close()
end
if str=="" then -- take no output as a failure (we can't tell..)
Print("hi")
str= nil
end
-- Remove terminating linefeed, if any (eases up one-line analysis)
--
if str then
if string.sub( str, -1 ) == '\n' then
str= string.sub( str, 1, -2 )
end
end
return str
end
local function Loc_DirCmd( cmd )
Print(cmd)
local str= Loc_ShellCommand( cmd )
return Loc_Lines(str)
end
local function Loc_DirList( dirname )
local ret= {}
local lookup= {}
local tbl= Loc_DirCmd( "dir /AD /B "..dirname ) -- only dirs
-- Add slash to every dir line
--
for i,v in ipairs(tbl) do
table.insert( ret, v..'\\' )
lookup[v]= true
end
-- Return with forward slashes
--
if true then
for i=1,table.getn(ret) do
ret[i]= string.gsub( ret[i], '\\', '/' )
Print (ret[i])
end
end
return ret
end
Loc_DirList("C:\\Program Files\\")
I hate having to install libraries (especially those that want me to use installer packages to install them). If you're looking for a clean solution for a directory listing on an absolute path in Lua, look no further.
Building on the answer that sylvanaar provided, I created a function that returns an array of all the files for a given directory (absolute path required). This is my preferred implementation, as it works on all my machines.
-- Lua implementation of PHP scandir function
function scandir(directory)
local i, t, popen = 0, {}, io.popen
local pfile = popen('ls -a "'..directory..'"')
for filename in pfile:lines() do
i = i + 1
t[i] = filename
end
pfile:close()
return t
end
If you are using Windows, you'll need to have a bash client installed so that the 'ls' command will work - alternately, you can use the dir command that sylvanaar provided:
'dir "'..directory..'" /b /ad'
Take the easy way, install lfs. Then use the following constructs to find what you need:
require'lfs'
for file in lfs.dir[[C:\Program Files]] do
if lfs.attributes(file,"mode") == "file" then print("found file, "..file)
elseif lfs.attributes(file,"mode")== "directory" then print("found dir, "..file," containing:")
for l in lfs.dir("C:\\Program Files\\"..file) do
print("",l)
end
end
end
notice that a backslash equals [[\]] equals "\\", and that in windows / is also allowed if not used on the cmd itself (correct me if I'm wrong on this one).
for dir in io.popen([[dir "C:\Program Files\" /b /ad]]):lines() do print(dir) end
*For Windows
Outputs:
Adobe
Bitcasa
Bonjour
Business Objects
Common Files
DVD Maker
IIS
Internet Explorer
iPod
iTunes
Java
Microsoft Device Emulator
Microsoft Help Viewer
Microsoft IntelliPoint
Microsoft IntelliType Pro
Microsoft Office
Microsoft SDKs
Microsoft Security Client
Microsoft SQL Server
Microsoft SQL Server Compact Edition
Microsoft Sync Framework
Microsoft Synchronization Services
Microsoft Visual Studio 10.0
Microsoft Visual Studio 9.0
Microsoft.NET
MSBuild
...
Each time through the loop you are given a new folder name. I chose to print it as an example.
I don't like installing libraries either and am working on an embedded device with less memory power then a pc. I found out that using 'ls' command lead to an out of memory. So I created a function that uses 'find' to solve the problem.
This way it was possible to keep memory usage steady and loop all the 30k files.
function dirLookup(dir)
local p = io.popen('find "'..dir..'" -type f') --Open directory look for files, save data in p. By giving '-type f' as parameter, it returns all files.
for file in p:lines() do --Loop through all files
print(file)
end
end
IIRC, getting the directory listing isn't possible with stock Lua. You need to write some glue code yourself, or use LuaFileSystem. The latter is most likely the path of least resistance for you. A quick scan of the docs shows lfs.dir() which will provide you with an iterator you can use to get the directories you are looking for. At that point, you can then do your string comparison to get the specific directories you need.
You also install and use the 'paths' module. Then you can easily do this as follow:
require 'paths'
currentPath = paths.cwd() -- Current working directory
folderNames = {}
for folderName in paths.files(currentPath) do
if folderName:find('$') then
table.insert(folderNames, paths.concat(currentPath, folderName))
end
end
print (folderNames)
-- This will print all folder names
Optionally, you can also look for file names with a specific extension by replacing fileName:find('$') with fileName:find('txt' .. '$')
If you're running on a Unix-based machine you can get a numerically-sorted list of files using the following code:
thePath = '/home/Your_Directory'
local handle = assert(io.popen('ls -1v ' .. thePath))
local allFileNames = string.split(assert(handle:read('*a')), '\n')
print (allFileNames[1]) -- This will print the first file name
The second code also excludes files such as '.' and '..'. So it's good to go!
Don't parse ls, it's evil! Use find with zero-terminated strings instead (on linux):
function scandir(directory)
local i, t = 0, {}
local pfile = assert(io.popen(("find '%s' -maxdepth 1 -print0"):format(directory), 'r'))
local list = pfile:read('*a')
pfile:close()
for filename in s:gmatch('[^\0]+')
i = i + 1
t[i] = filename
end
return t
end
WARNING: however, as an acceped answer this apporach could be exploited if directory name contain ' in it. Only one safe solution is to use lfs or other special library.
Few fixes of val says Reinstate Monica solution:
function scandir(directory)
local pfile = assert(io.popen(("find '%s' -mindepth 1 -maxdepth 1 -type d -printf '%%f\\0'"):format(directory), 'r'))
local list = pfile:read('*a')
pfile:close()
local folders = {}
for filename in string.gmatch(list, '[^%z]+') do
table.insert(folders, filename)
end
return folders
end
Now it filters by folders, excludes dir itself and prints only names.
Anyone know a good solution?
So far I have not found a better way than using File>New file and then copying contents from old file to new.
You can probably duplicate in Finder and re-import but that's almost same amount of work: switching to finder, duplicate, import new files.
Doing this with one class is not so hard, but what to do if you need to generate 10+ similar Classes based on superclass.
In Eclipse you select file and then copy/paste it in same folder. In finder there's Duplicate.
There's a menu Edit > Duplicate. But it's ALWAYS disabled. I tried selecting various files, classes, methods. It's still disabled.
In XCode 4.2 (I know this is an old question) there is Duplicate under the File menu.
Select the file (you can select multiple files but it doesn't appear to do anything useful) in the Project Navigator and then File->Duplicate. Hooray!
In Xcode 4.5 we can duplicate using File-> Duplicate or cmd + shift + S
"Duplicate" is enabled for targets in XCode (pretty much nothing else that I know of).
If you have a substantial number of subclasses with the same starting point to replicate, why not make a class template from it? Then you can just use file->New to make new instances. It's fairly quick to do.
This is probably the simplest example:
http://www.macresearch.org/custom_xcode_templates
Otherwise, I'd simply duplicate the files in Finder as many times as you need, name them, and drag them into XCode en-masse.
Careful!
When you use duplicate ( CMD + Shift + S ) - Xcode have a problem with indexing headers.
Also when u want to make a refactoring it can be next error window:
So there a couple of ways what to do, to fix that.
Delete derived data from menu Window > Projects. Restart Xcode.
Product > Clean
You could use "Save As..."; you'd still have to go back and re-add the original files to the project, though.
It wouldn't be such a bad way to do a bunch of related classes, though: edit file, Save As "class2", edit file, Save As "class3", etc., then "Add Existing Files" and re-add all of the files but the last to your project.
I use the following perl script to duplicate a file pair in the Terminal. You give it the base name of the original and new file, and it copies the header and implementation (c/cpp/m/mm) file, then replaces all occurances of the base name with the new name, then adds them to subversion. You still have to add the new files in to Xcode and adjust the creation date in the comment (I've got a Keyboard Maestro macro for that), but its quicker than doing a lot of the steps manually. I operate with a Terminal window and four tabs pre-set to the Project, Source, Resources, and English.lproj directory which gives quick access for a lot of operations.
#!/usr/bin/perl
use lib "$ENV{HOME}/perl";
use warnings;
use strict;
our $cp = '/bin/cp';
our $svn = '/usr/bin/svn';
our $perl = '/usr/bin/perl';
our $source = shift;
our $add = 1;
if ( $source =~ m!^-! ) {
if ( $source eq '-a' || $source eq '--add' ) {
$add = 1;
$source = shift;
} elsif ( $source eq '-A' || $source eq '--noadd' ) {
$add = undef;
$source = shift;
} else {
die "Bad arg $source";
}
}
our $dest = shift;
die "Bad source $source" unless $source =~ m!^(.*/)?[A-Za-z0-9]+$!;
die "Bad dest $dest" unless $dest =~ m!^(.*/)?[A-Za-z0-9]+$!;
my $cpp;
$cpp = 'c' if ( -e "$source.c" );
$cpp = 'cpp' if ( -e "$source.cpp" );
$cpp = 'mm' if ( -e "$source.mm" );
$cpp = 'm' if ( -e "$source.m" );
die "Missing source $source" unless -e "$source.h" && -e "$source.$cpp";
die "Existing dest $dest" if -e "$dest.h" && -e "$dest.$cpp";
our $sourcename = $source; $sourcename =~ s!.*/!!;
our $destname = $dest; $destname =~ s!.*/!!;
print "cp $source.h $dest.h\n";
system( $cp, "$source.h", "$dest.h" );
print "s/$sourcename/$destname in $dest.h\n";
system( $perl, '-p', '-i', '-e', "s/$sourcename/$destname/g", "$dest.h" );
print "cp $source.$cpp $dest.$cpp\n";
system( $cp, "$source.$cpp", "$dest.$cpp" );
print "s/$sourcename/$destname in $dest.$cpp\n";
system( $perl, '-p', '-i', '-e', "s/$sourcename/$destname/g", "$dest.$cpp" );
if ( $add ) {
print "svn add $dest.$cpp $dest.h\n";
system( $svn, 'add', "$dest.$cpp", "$dest.h" );
}
In my case, one of my folder changed from one place to another place.
I have "Home" folder in Controller folder, but unfortunately it's moved from Controller folder to Manager folder.
I checked many times everything fine, but I'm getting Command PrecompileSwiftBridgingHeader failed with a nonzero exit code
But after 2 hours i realised, my folder structure changed.