profile
viewpoint
Simon Sawert bombsimon @devcodeswe, Stim Stockholm, Sweden https://sawert.se

0x4b53/amqp-rpc 8

Framework to use RabbitMQ as RPC

bombsimon/det-blev-ingen-cd.com 8

💿 Source code for the web site

0x4b53/epp-go 2

EPP server and client written in Go

bombsimon/gorm-bulk 2

🛢 Perform bulk actions with Gorm

bombsimon/dotfiles 1

💻 ...

bombsimon/elixir-nm 1

Nim implementation with Elixir

bombsimon/flickr-upload 1

Yet another API implementation

bombsimon/advent-of-code-2019 0

🎄Solutions to advent of code 2019

bombsimon/alcohol-diary 0

🍻 iOS application to keep track of alcohol consumption

bombsimon/amqp 0

Go client for AMQP 0.9.1

issue commentbombsimon/wsl

Enforce cuddling of error checks

Thanks for the issue!

Yeah that would be cool! I agree that the recommended way is to cuddle the error with the assignment in your example (and that's why it's allowed/supported).

I started working on fixing the errors and noticed that I had some design flaws I wanted to address first. I lost track a bit but I intend to pick up where I left and improve on this linter. When I do I'll add this feature as well!

If someone wants to create a PR in the meanwhile that's very welcomed!

JDiPierro

comment created time in a day

issue commentcjbassi/ytop

macOS support

@cjbassi Works like a charm! Thanks!

image

cjbassi

comment created time in a day

issue commentcjbassi/ytop

macOS support

@martinlindhe Yeah I saw the checkboxes but obviously i misunderstood what everything except the process filtering ment. I'll keep an eye on the checkboxes in the future instead. Thanks.

cjbassi

comment created time in 2 days

issue commentcjbassi/ytop

macOS support

@martinlindhe Sorry if I'm stupid but the first post doesn't mention the branch where progress is made.

@cjbassi posted 23 hours ago:

I've been doing some macos work, can you test that it works now?

To which @for-coursera responded:

And everything seems to be OK except the process filtering (this / hotkey) doesn't seem to function :)

I assumed that "everything" in this cases included disk usage and temperatures so that's why I asked for the branch instead of the box to be ticked.

cjbassi

comment created time in 2 days

issue commentcjbassi/ytop

macOS support

@for-coursera: Are you building this from master? I tried to build from that branch just now and I still don't have the disk usage or temperatures working.

Btw if it's of interest I get the same errors as posted above (same version of rustc and rustup, macOS 10.15.1).

cjbassi

comment created time in 2 days

push eventbombsimon/gorm-bulk

han0110

commit sha c0dadceef9a1211eacd0496cde6f80becc132155

Fix inconsistent timestamp when concurrent usage

view details

han0110

commit sha 5918ad5b84490b15cc51de06efdc511fc1a45f0c

Add test for modification of CreatedAt and UpdatedAt (by bombsimon)

view details

han0110

commit sha e282d1055f4c3490d103593ef631b4964d926047

Add test case for multiple records with empty timestamp

view details

push time in 3 days

PR merged bombsimon/gorm-bulk

Fix inconsistent timestamp when concurrent usage

With global variable bulkNow, we may encounter inconsistent CreatedAt and UpdatedAt in different rows at the same BulkInsert when concurrent usage (Someone might have just called the defer function and set the bulkNow to time.Time{} while the other one is calling ObjectToMap).

So I remove the global variable and need to change the return value of ObjectToMap to get the .Struct.Name of the field to check if it is CreatedAt or UpdatedAt, then set the value to bulkNow at last moment.

+161 -33

6 comments

2 changed files

han0110

pr closed time in 3 days

pull request commentbombsimon/gorm-bulk

Fix inconsistent timestamp when concurrent usage

Thank you so much for the investigation! If the gorm interface assumes pointers then that would be better to support. The MyTypeToInterfaceSlice could be responsible for creating pointers for each element added to the slice, then the end user may work with any preferred type but this package ensures that pointers are created.

It will be a bit too much to refactor since all the tests needs to be re-written so I totally get that you don't mind doing it in this PR.

Feel free to create an issue summarising what you've found out and I'll try to fix that as soon as possible!

han0110

comment created time in 3 days

pull request commentbombsimon/gorm-bulk

Fix inconsistent timestamp when concurrent usage

No worries at all, this is a great catch! I've created a new test so you can do som TDD if you want to! We still want these tests when you're all finished! I'll try to help later if you need but right now I need to work. Please add this test!

diff --git a/gorm_bulk_test.go b/gorm_bulk_test.go
index dedbc65..d4ed629 100644
--- a/gorm_bulk_test.go
+++ b/gorm_bulk_test.go
@@ -430,3 +430,103 @@ func Test_columnOrder(t *testing.T) {
 		})
 	}
 }
+
+func Test_Timestamps(t *testing.T) {
+	db, _, err := sqlmock.New()
+	require.NoError(t, err)
+
+	gdb, err := gorm.Open("mysql", db)
+	require.NoError(t, err)
+
+	pastDate := time.Date(1985, 1, 1, 0, 0, 0, 0, time.UTC)
+	testStartedAt := time.Now()
+
+	cases := []struct {
+		description string
+		slice       []interface{}
+		expectedSQL string
+		validFunc   func(t *testing.T, vars []interface{})
+	}{
+		{
+			description: "set dates will persist",
+			slice: []interface{}{
+				struct {
+					Foo       string
+					CreatedAt time.Time
+					UpdatedAt time.Time
+				}{
+					Foo:       "this is foo",
+					CreatedAt: pastDate,
+					UpdatedAt: pastDate,
+				},
+			},
+			expectedSQL: "INSERT INTO `` (`created_at`, `foo`, `updated_at`) VALUES (?, ?, ?)",
+			validFunc: func(t *testing.T, vars []interface{}) {
+				createdAt, updatedAt := vars[0], vars[2]
+				assert.Equal(t, pastDate, createdAt)
+				assert.Equal(t, pastDate, updatedAt)
+			},
+		},
+		{
+			description: "empty time pointers will be set to now func",
+			slice: []interface{}{
+				struct {
+					Foo       string
+					CreatedAt *time.Time
+					UpdatedAt *time.Time
+				}{
+					Foo: "this is foo",
+				},
+			},
+			expectedSQL: "INSERT INTO `` (`created_at`, `foo`, `updated_at`) VALUES (?, ?, ?)",
+			validFunc: func(t *testing.T, vars []interface{}) {
+				createdAt, updatedAt := vars[0], vars[2]
+
+				createdAtTime, ok := createdAt.(*time.Time)
+				assert.True(t, ok)
+				assert.True(t, createdAtTime.After(testStartedAt))
+
+				updatedAtTime, ok := updatedAt.(*time.Time)
+				assert.True(t, ok)
+				assert.True(t, updatedAtTime.After(testStartedAt))
+			},
+		},
+		{
+			description: "empty time will be set to now func",
+			slice: []interface{}{
+				struct {
+					Foo       string
+					CreatedAt time.Time
+					UpdatedAt time.Time
+				}{
+					Foo: "this is foo",
+				},
+			},
+			expectedSQL: "INSERT INTO `` (`created_at`, `foo`, `updated_at`) VALUES (?, ?, ?)",
+			validFunc: func(t *testing.T, vars []interface{}) {
+				createdAt, updatedAt := vars[0], vars[2]
+
+				createdAtTime, ok := createdAt.(time.Time)
+				assert.True(t, ok)
+				assert.True(t, createdAtTime.After(testStartedAt))
+
+				updatedAtTime, ok := updatedAt.(time.Time)
+				assert.True(t, ok)
+				assert.True(t, updatedAtTime.After(testStartedAt))
+			},
+		},
+	}
+
+	for _, tc := range cases {
+		t.Run(tc.description, func(t *testing.T) {
+			scope, err := scopeFromObjects(gdb, tc.slice, InsertFunc)
+
+			require.NotNil(t, scope)
+			require.NoError(t, err)
+
+			assert.Equal(t, tc.expectedSQL, scope.SQL)
+
+			tc.validFunc(t, scope.SQLVars)
+		})
+	}
+}
han0110

comment created time in 3 days

pull request commentbombsimon/gorm-bulk

Fix inconsistent timestamp when concurrent usage

So I wrote a test for this because it seems it was missing and that was a good idea.

- (time.Time) 2020-01-23 07:58:28.522377 +0100 CET m=+0.002462155,
+ (time.Time) 0001-01-01 00:00:00 +0000 UTC,
  (string) (len=11) "this is foo",
- (time.Time) 2020-01-23 07:58:28.522377 +0100 CET m=+0.002462155
+ (time.Time) 0001-01-01 00:00:00 +0000 UTC

Since I got the empty value I tried to debug what we're setting and what the field value ended up being:

if field.IsBlank {
    _ = field.Set(bulkNow)

    fmt.Println(bulkNow)
    fmt.Println(field.Field.Interface())
}

This ended up giving me:

2020-01-23 07:58:28.52324 +0100 CET m=+0.003324871
0001-01-01 00:00:00 +0000 UTC

So I thought, let's error check this:

if err := field.Set(bulkNow); err != nil {
    panic(err)
}

And lo and behold, this gives me:

panic: using unaddressable value [recovered]
        panic: using unaddressable value

I don't really have the time to dig into this now but would be nice to adress this before merging!

han0110

comment created time in 3 days

Pull request review commentbombsimon/gorm-bulk

Fix inconsistent timestamp when concurrent usage

 func scopeFromObjects(db *gorm.DB, objects []interface{}, execFunc ExecFunc) (*g 		}  		for _, key := range columnNames {-			objectScope.AddToVars(row[key])+			// Column CreatedAt and UpdatedAt with zero value will be set to same time+			if name := row[key].Struct.Name; name == "CreatedAt" || name == "UpdatedAt" {+				if t, ok := row[key].Field.Interface().(time.Time); ok && t.IsZero() {+					_ = row[key].Set(bulkNow)

You’re right, I’m stupid. That was the whole idea behind this in the first place. :)

Keep the variable, dump the comment. Maaaybe keep s comment about why it’s there, like nowFunc is stored first to result in the same time for every record* or whatever. You can decide if and what! :)

han0110

comment created time in 3 days

Pull request review commentbombsimon/gorm-bulk

Fix inconsistent timestamp when concurrent usage

 func scopeFromObjects(db *gorm.DB, objects []interface{}, execFunc ExecFunc) (*g 		}  		for _, key := range columnNames {-			objectScope.AddToVars(row[key])+			// Column CreatedAt and UpdatedAt with zero value will be set to same time+			if name := row[key].Struct.Name; name == "CreatedAt" || name == "UpdatedAt" {+				if t, ok := row[key].Field.Interface().(time.Time); ok && t.IsZero() {+					_ = row[key].Set(bulkNow)
					_ = row[key].Set(gorm.NowFunc())
han0110

comment created time in 4 days

Pull request review commentbombsimon/gorm-bulk

Fix inconsistent timestamp when concurrent usage

 func scopeFromObjects(db *gorm.DB, objects []interface{}, execFunc ExecFunc) (*g 		}  		for _, key := range columnNames {-			objectScope.AddToVars(row[key])+			// Column CreatedAt and UpdatedAt with zero value will be set to same time+			if name := row[key].Struct.Name; name == "CreatedAt" || name == "UpdatedAt" {+				if t, ok := row[key].Field.Interface().(time.Time); ok && t.IsZero() {

I might be wrong but I'm pretty sure CreatedAt and UpdatedAt can be pointers (even though they're not in the gorm.Model type). If so, this type casting can fail since the value might be nil and not a zero time. If that's the case we still want to set the default bulk time, don't we?

han0110

comment created time in 4 days

Pull request review commentbombsimon/gorm-bulk

Fix inconsistent timestamp when concurrent usage

 func scopeFromObjects(db *gorm.DB, objects []interface{}, execFunc ExecFunc) (*g 		placeholders      []string 		groups            []string 		scope             = db.NewScope(objects[0])+		// bulkNow holds a global now state and will be used for each records as

Since you can no longer inject your own NowFunc() (although still manipulate the gorm.NowFunc()) you should drop this commend and the variable and just call gorm.NowFunc() where it's used.

han0110

comment created time in 4 days

pull request commentbombsimon/gorm-bulk

Fix inconsistent timestamp when concurrent usage

Thanks for this, nice catch!

I know I did this in a weird way because I had something in mind where you would be able to set your own time but also have the same time for all inserts. I guess I didn't really thing this through regarding running the function in several go routines. I'm actually not really sure about the thread safety at all for this package. :)

I'll have a look at this today!

han0110

comment created time in 4 days

push eventbombsimon/pace-calculator

Simon Sawert

commit sha ac204bdd9e0d377263f1bfc1ea45a0fc7bf53097

Remove duplicate root path

view details

Simon Sawert

commit sha 989a2a1c3627d8533d8795f6a1fdc63feb32d490

Ignore compiled css

view details

push time in 6 days

push eventbombsimon/csgo-config

Simon Sawert

commit sha e30ae6a017fda03e333631353165447c045029d6

I believe in your crosshair, olofm!

view details

push time in 7 days

push eventbombsimon/csgo-config

Simon Sawert

commit sha c990fecf8ed76334f02920dc372788086d163f5b

Don't use crosshair dot

view details

push time in 7 days

starteddillonkearns/mobster

started time in 9 days

created tagbombsimon/tld-validator

tagv1.1.1

🌍 Top level domains with Go

created time in 10 days

release bombsimon/tld-validator

v1.1.1

released time in 10 days

push eventbombsimon/tld-validator

Simon Sawert

commit sha 3e7afdd0bc7efb6e3b35099207667f9f30c53499

🆕 Re-generate TLD list, bump dependencies

view details

push time in 10 days

push eventbombsimon/tld-validator

Simon Sawert

commit sha 47f58866ff763914e53ee379efe00a572a6e4206

🆕 Re-generate TLD list, bump dependencies

view details

push time in 10 days

push eventbombsimon/tld-validator

Simon Sawert

commit sha 5d3989e3fe3ec1aafb6d3859f6dfe4598d5220c5

Re-generate TLD list

view details

push time in 10 days

created tagbombsimon/mysql-error-numbers

tagv1.0.0

⛔️ Constants for all MySQL error numbers

created time in 10 days

release bombsimon/mysql-error-numbers

v1.0.0

released time in 10 days

push eventbombsimon/mysql-error-numbers

Simon Sawert

commit sha 33793c6d60fd6925867e857b770ffa5e7559a0be

Re-generate codes, update dependencies

view details

push time in 10 days

issue commentpaulrosania/go-charset

charset error Golang 1.10.3 in custom GOPATH

@paulrosania Any news on this? Would you be open to a PR or do you recommend using another package instead of this one?

sandermirov

comment created time in 11 days

startedhakluke/how-to-exit-vim

started time in 11 days

pull request commentt-tiger/gorm-bulk-insert

Fixed bulkinsert swallowing error from exec

@EdmundLeex No worries, I just wanted to make sure I didn't miss anything! Keep the issues coming if you find any problems related to the code!

EdmundLeex

comment created time in 11 days

startedwireservice/csvkit

started time in 12 days

issue commentstreadway/amqp

amqp installed but not loaded with php7.4

This project is for the Go client, you probably want to create your issue in pdezwart/php-amqp.

easternmayurt

comment created time in 12 days

issue closedvlang/vid

Build error: incompatible integer to pointer conversion

OS

System Version: macOS 10.15.1 (19B88)
Kernel Version: Darwin 19.0.0

V

$ v --version
V 0.1.24 25e7cee

vid

$ git rev-parse --verify HEAD
f8cb1f3715cf96c0eca834b6273baf26d2a07468

Build

$ v .
/private/var/folders/q3/bf76j42160j2nt4s2tz1_fd40000gn/T/v/vid.tmp.c:4216:7: warning: incompatible integer to pointer conversion initializing 'void *' with an expression of type 'int' [-Wint-conversio...
(Use `v -g` to print the entire error message)

V error: C error. This should never happen.
Please create a GitHub issue: https://github.com/vlang/v/issues/new/choose

<details><summary>Full error message</summary>

C compiler=cc
/Users/x/git/v/vlib/gl/gl.v:15:7: warning: incompatible integer to pointer conversion initializing 'void *' with an expression of type 'int' [-Wint-conversion]
void* ok= gladLoadGL ( ) ;
      ^   ~~~~~~~~~~~~~~
/Users/x/git/v/vlib/gl/gl.v:43:34: warning: incompatible pointer types passing 'byte **' (aka 'unsigned char **') to parameter of type 'const GLchar *const *' (aka 'const char *const *') [-Wincompatible-pointer-types]
 glShaderSource ( shader ,  a ,  & source .str ,  b ) ;
                                 ^~~~~~~~~~~~~
/Users/x/git/v/vlib/gl/gl.v:43:51: warning: incompatible integer to pointer conversion passing 'int' to parameter of type 'const GLint *' (aka 'const int *'); take the address with & [-Wint-conversion]
 glShaderSource ( shader ,  a ,  & source .str ,  b ) ;
                                                  ^
                                                  &
/Users/x/git/v/vlib/gl/gl.v:77:45: warning: passing 'byte [512]' to parameter of type 'GLchar *' (aka 'char *') converts between pointers to integer types with different sign [-Wpointer-sign]
 glGetShaderInfoLog ( shader ,  512 ,  0 ,  info_log ) ;
                                            ^~~~~~~~
/Users/x/git/v/vlib/gl/gl.v:83:48: warning: passing 'byte [1024]' to parameter of type 'GLchar *' (aka 'char *') converts between pointers to integer types with different sign [-Wpointer-sign]
 glGetProgramInfoLog ( program ,  1024 ,  0 ,  info_log ) ;
                                               ^~~~~~~~
/Users/x/git/v/vlib/gl/gl.v:147:43: warning: incompatible integer to pointer conversion passing 'int' to parameter of type 'const void *' [-Wint-conversion]
 glDrawElements ( mode ,  count ,  typ ,  indices ) ;
                                          ^~~~~~~
/Users/x/git/v/vlib/gl/gl.v:177:74: warning: incompatible integer to pointer conversion passing 'int' to parameter of type 'const void *' [-Wint-conversion]
 glVertexAttribPointer ( index ,  size ,  typ ,  normalized ,  stride ,  ptr ) ;
                                                                         ^~~
/Users/x/git/v/vlib/stbi/stbi.v:52:39: warning: passing 'char *' to parameter of type 'const stbi_uc *' (aka 'const unsigned char *') converts between pointers to integer types with different sign [-Wpointer-sign]
 res .data  =  stbi_load_from_memory ((char*) buf ,  3812 ,  & res .width ,  & res .height ,  & res .nr_channels ,  flag ) ;
                                      ^~~~~~~~~~~
/Users/x/git/v/thirdparty/stb_image/stb_image.h:1287:55: note: passing argument to parameter 'buffer' here
STBIDEF stbi_uc *stbi_load_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp)
                                                      ^
/Users/x/git/v/vlib/uiold/ui_darwin.v:28:2: warning: incompatible function pointer types passing 'void (*)(void *, void *, void *)' to parameter of type 'EventHandlerUPP' (aka 'int (*)(struct OpaqueEventHandlerCallRef *, struct OpaqueEventRef *, void *)') [-Wincompatible-function-pointer-types]
 InstallApplicationEventHandler(&uiold__focus_app, 1, &eventType, NULL, NULL);
 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Carbon.framework/Frameworks/HIToolbox.framework/Headers/CarbonEvents.h:15098:57: note: expanded from macro 'InstallApplicationEventHandler'
      InstallEventHandler( GetApplicationEventTarget(), (handler), (numTypes), (list), (userData), (outHandlerRef) )
                                                        ^~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Carbon.framework/Frameworks/HIToolbox.framework/Headers/CarbonEventsCore.h:2594:26: note: passing argument to parameter 'inHandler' here
  EventHandlerUPP        inHandler,
                         ^
/Users/x/git/v/vlib/glfw/glfw.v:247:23: warning: incompatible integer to pointer conversion passing 'int' to parameter of type 'GLFWcursor *' (aka 'struct GLFWcursor *') [-Wint-conversion]
 glfwSetCursor ( 0 ,  GLFW_IBEAM_CURSOR ) ;
                      ^~~~~~~~~~~~~~~~~
/Users/x/git/v/thirdparty/glfw/GLFW/glfw3.h:1051:37: note: expanded from macro 'GLFW_IBEAM_CURSOR'
#define GLFW_IBEAM_CURSOR           0x00036002
                                    ^~~~~~~~~~
/Users/x/git/v/thirdparty/glfw/GLFW/glfw3.h:4329:60: note: passing argument to parameter 'cursor' here
GLFWAPI void glfwSetCursor(GLFWwindow* window, GLFWcursor* cursor);
                                                           ^
/Users/x/git/v/vlib/glfw/glfw.v:252:30: warning: incompatible integer to pointer conversion passing 'int' to parameter of type 'GLFWcursor *' (aka 'struct GLFWcursor *') [-Wint-conversion]
 glfwSetCursor ( w ->data ,  GLFW_IBEAM_CURSOR ) ;
                             ^~~~~~~~~~~~~~~~~
/Users/x/git/v/thirdparty/glfw/GLFW/glfw3.h:1051:37: note: expanded from macro 'GLFW_IBEAM_CURSOR'
#define GLFW_IBEAM_CURSOR           0x00036002
                                    ^~~~~~~~~~
/Users/x/git/v/thirdparty/glfw/GLFW/glfw3.h:4329:60: note: passing argument to parameter 'cursor' here
GLFWAPI void glfwSetCursor(GLFWwindow* window, GLFWcursor* cursor);
                                                           ^
/Users/x/git/v/vlib/glfw/glfw.v:272:14: warning: initializing 'GLFWvidmode *' (aka 'struct GLFWvidmode *') with an expression of type 'const GLFWvidmode *' (aka 'const struct GLFWvidmode *') discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
GLFWvidmode* mode= glfwGetVideoMode ( glfwGetPrimaryMonitor ( ) ) ;
             ^     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/x/git/v/vlib/glm/glm.v:254:31: warning: incompatible integer to pointer conversion assigning to 'f32 *' (aka 'float *') from 'int' [-Wint-conversion]
 res [/*ptr!*/ 0 ]/*rf32 1*/  =  1 ;
                              ^  ~
/Users/x/git/v/vlib/glm/glm.v:255:31: warning: incompatible integer to pointer conversion assigning to 'f32 *' (aka 'float *') from 'int' [-Wint-conversion]
 res [/*ptr!*/ 5 ]/*rf32 1*/  =  1 ;
                              ^  ~
/Users/x/git/v/vlib/glm/glm.v:256:32: warning: incompatible integer to pointer conversion assigning to 'f32 *' (aka 'float *') from 'int' [-Wint-conversion]
 res [/*ptr!*/ 10 ]/*rf32 1*/  =  1 ;
                               ^  ~
/Users/x/git/v/vlib/glm/glm.v:261:32: warning: incompatible integer to pointer conversion assigning to 'f32 *' (aka 'float *') from 'int' [-Wint-conversion]
 res [/*ptr!*/ 15 ]/*rf32 1*/  =  1 ;
                               ^  ~
/Users/x/git/v/vlib/freetype/freetype.v:116:23: warning: passing 'int *' to parameter of type 'GLuint *' (aka 'unsigned int *') converts between pointers to integer types with different sign [-Wpointer-sign]
 glGenTextures ( 1 ,  & texture ) ;
                      ^~~~~~~~~
/Users/x/git/v/vlib/freetype/freetype.v:168:7: warning: incompatible integer to pointer conversion initializing 'void *' with an expression of type 'FT_Error' (aka 'int') [-Wint-conversion]
void* ret= FT_Init_FreeType ( & ft ) ;
      ^    ~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/x/git/v/vlib/freetype/freetype.v:188:7: warning: incompatible integer to pointer conversion assigning to 'void *' from 'int' [-Wint-conversion]
 ret  =  ((int)( FT_New_Face ( ft , (char*) font_path .str ,  0 ,  & face ) ) ) ;
      ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
19 warnings generated.
ld: warning: directory not found for option '-L/opt/local/lib'
ld: library not found for -lglfw
clang: error: linker command failed with exit code 1 (use -v to see invocation)
V error: C error. This should never happen. 
Please create a GitHub issue: https://github.com/vlang/v/issues/new/choose

</details>

closed time in 12 days

bombsimon

issue commentvlang/vid

Build error: incompatible integer to pointer conversion

My bad, this isn't related to vid so I'll add this issue in v instead.

bombsimon

comment created time in 12 days

issue openedvlang/vid

Build error: incompatible integer to pointer conversion

OS

System Version: macOS 10.15.1 (19B88)
Kernel Version: Darwin 19.0.0

V

$ v --version
V 0.1.24 25e7cee

vid

$ git rev-parse --verify HEAD
f8cb1f3715cf96c0eca834b6273baf26d2a07468

Build

$ v .
/private/var/folders/q3/bf76j42160j2nt4s2tz1_fd40000gn/T/v/vid.tmp.c:4216:7: warning: incompatible integer to pointer conversion initializing 'void *' with an expression of type 'int' [-Wint-conversio...
(Use `v -g` to print the entire error message)

V error: C error. This should never happen.
Please create a GitHub issue: https://github.com/vlang/v/issues/new/choose

<details><summary>Full error message</summary>

C compiler=cc
/Users/x/git/v/vlib/gl/gl.v:15:7: warning: incompatible integer to pointer conversion initializing 'void *' with an expression of type 'int' [-Wint-conversion]
void* ok= gladLoadGL ( ) ;
      ^   ~~~~~~~~~~~~~~
/Users/x/git/v/vlib/gl/gl.v:43:34: warning: incompatible pointer types passing 'byte **' (aka 'unsigned char **') to parameter of type 'const GLchar *const *' (aka 'const char *const *') [-Wincompatible-pointer-types]
 glShaderSource ( shader ,  a ,  & source .str ,  b ) ;
                                 ^~~~~~~~~~~~~
/Users/x/git/v/vlib/gl/gl.v:43:51: warning: incompatible integer to pointer conversion passing 'int' to parameter of type 'const GLint *' (aka 'const int *'); take the address with & [-Wint-conversion]
 glShaderSource ( shader ,  a ,  & source .str ,  b ) ;
                                                  ^
                                                  &
/Users/x/git/v/vlib/gl/gl.v:77:45: warning: passing 'byte [512]' to parameter of type 'GLchar *' (aka 'char *') converts between pointers to integer types with different sign [-Wpointer-sign]
 glGetShaderInfoLog ( shader ,  512 ,  0 ,  info_log ) ;
                                            ^~~~~~~~
/Users/x/git/v/vlib/gl/gl.v:83:48: warning: passing 'byte [1024]' to parameter of type 'GLchar *' (aka 'char *') converts between pointers to integer types with different sign [-Wpointer-sign]
 glGetProgramInfoLog ( program ,  1024 ,  0 ,  info_log ) ;
                                               ^~~~~~~~
/Users/x/git/v/vlib/gl/gl.v:147:43: warning: incompatible integer to pointer conversion passing 'int' to parameter of type 'const void *' [-Wint-conversion]
 glDrawElements ( mode ,  count ,  typ ,  indices ) ;
                                          ^~~~~~~
/Users/x/git/v/vlib/gl/gl.v:177:74: warning: incompatible integer to pointer conversion passing 'int' to parameter of type 'const void *' [-Wint-conversion]
 glVertexAttribPointer ( index ,  size ,  typ ,  normalized ,  stride ,  ptr ) ;
                                                                         ^~~
/Users/x/git/v/vlib/stbi/stbi.v:52:39: warning: passing 'char *' to parameter of type 'const stbi_uc *' (aka 'const unsigned char *') converts between pointers to integer types with different sign [-Wpointer-sign]
 res .data  =  stbi_load_from_memory ((char*) buf ,  3812 ,  & res .width ,  & res .height ,  & res .nr_channels ,  flag ) ;
                                      ^~~~~~~~~~~
/Users/x/git/v/thirdparty/stb_image/stb_image.h:1287:55: note: passing argument to parameter 'buffer' here
STBIDEF stbi_uc *stbi_load_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp)
                                                      ^
/Users/x/git/v/vlib/uiold/ui_darwin.v:28:2: warning: incompatible function pointer types passing 'void (*)(void *, void *, void *)' to parameter of type 'EventHandlerUPP' (aka 'int (*)(struct OpaqueEventHandlerCallRef *, struct OpaqueEventRef *, void *)') [-Wincompatible-function-pointer-types]
 InstallApplicationEventHandler(&uiold__focus_app, 1, &eventType, NULL, NULL);
 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Carbon.framework/Frameworks/HIToolbox.framework/Headers/CarbonEvents.h:15098:57: note: expanded from macro 'InstallApplicationEventHandler'
      InstallEventHandler( GetApplicationEventTarget(), (handler), (numTypes), (list), (userData), (outHandlerRef) )
                                                        ^~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Carbon.framework/Frameworks/HIToolbox.framework/Headers/CarbonEventsCore.h:2594:26: note: passing argument to parameter 'inHandler' here
  EventHandlerUPP        inHandler,
                         ^
/Users/x/git/v/vlib/glfw/glfw.v:247:23: warning: incompatible integer to pointer conversion passing 'int' to parameter of type 'GLFWcursor *' (aka 'struct GLFWcursor *') [-Wint-conversion]
 glfwSetCursor ( 0 ,  GLFW_IBEAM_CURSOR ) ;
                      ^~~~~~~~~~~~~~~~~
/Users/x/git/v/thirdparty/glfw/GLFW/glfw3.h:1051:37: note: expanded from macro 'GLFW_IBEAM_CURSOR'
#define GLFW_IBEAM_CURSOR           0x00036002
                                    ^~~~~~~~~~
/Users/x/git/v/thirdparty/glfw/GLFW/glfw3.h:4329:60: note: passing argument to parameter 'cursor' here
GLFWAPI void glfwSetCursor(GLFWwindow* window, GLFWcursor* cursor);
                                                           ^
/Users/x/git/v/vlib/glfw/glfw.v:252:30: warning: incompatible integer to pointer conversion passing 'int' to parameter of type 'GLFWcursor *' (aka 'struct GLFWcursor *') [-Wint-conversion]
 glfwSetCursor ( w ->data ,  GLFW_IBEAM_CURSOR ) ;
                             ^~~~~~~~~~~~~~~~~
/Users/x/git/v/thirdparty/glfw/GLFW/glfw3.h:1051:37: note: expanded from macro 'GLFW_IBEAM_CURSOR'
#define GLFW_IBEAM_CURSOR           0x00036002
                                    ^~~~~~~~~~
/Users/x/git/v/thirdparty/glfw/GLFW/glfw3.h:4329:60: note: passing argument to parameter 'cursor' here
GLFWAPI void glfwSetCursor(GLFWwindow* window, GLFWcursor* cursor);
                                                           ^
/Users/x/git/v/vlib/glfw/glfw.v:272:14: warning: initializing 'GLFWvidmode *' (aka 'struct GLFWvidmode *') with an expression of type 'const GLFWvidmode *' (aka 'const struct GLFWvidmode *') discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
GLFWvidmode* mode= glfwGetVideoMode ( glfwGetPrimaryMonitor ( ) ) ;
             ^     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/x/git/v/vlib/glm/glm.v:254:31: warning: incompatible integer to pointer conversion assigning to 'f32 *' (aka 'float *') from 'int' [-Wint-conversion]
 res [/*ptr!*/ 0 ]/*rf32 1*/  =  1 ;
                              ^  ~
/Users/x/git/v/vlib/glm/glm.v:255:31: warning: incompatible integer to pointer conversion assigning to 'f32 *' (aka 'float *') from 'int' [-Wint-conversion]
 res [/*ptr!*/ 5 ]/*rf32 1*/  =  1 ;
                              ^  ~
/Users/x/git/v/vlib/glm/glm.v:256:32: warning: incompatible integer to pointer conversion assigning to 'f32 *' (aka 'float *') from 'int' [-Wint-conversion]
 res [/*ptr!*/ 10 ]/*rf32 1*/  =  1 ;
                               ^  ~
/Users/x/git/v/vlib/glm/glm.v:261:32: warning: incompatible integer to pointer conversion assigning to 'f32 *' (aka 'float *') from 'int' [-Wint-conversion]
 res [/*ptr!*/ 15 ]/*rf32 1*/  =  1 ;
                               ^  ~
/Users/x/git/v/vlib/freetype/freetype.v:116:23: warning: passing 'int *' to parameter of type 'GLuint *' (aka 'unsigned int *') converts between pointers to integer types with different sign [-Wpointer-sign]
 glGenTextures ( 1 ,  & texture ) ;
                      ^~~~~~~~~
/Users/x/git/v/vlib/freetype/freetype.v:168:7: warning: incompatible integer to pointer conversion initializing 'void *' with an expression of type 'FT_Error' (aka 'int') [-Wint-conversion]
void* ret= FT_Init_FreeType ( & ft ) ;
      ^    ~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/x/git/v/vlib/freetype/freetype.v:188:7: warning: incompatible integer to pointer conversion assigning to 'void *' from 'int' [-Wint-conversion]
 ret  =  ((int)( FT_New_Face ( ft , (char*) font_path .str ,  0 ,  & face ) ) ) ;
      ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
19 warnings generated.
ld: warning: directory not found for option '-L/opt/local/lib'
ld: library not found for -lglfw
clang: error: linker command failed with exit code 1 (use -v to see invocation)
V error: C error. This should never happen. 
Please create a GitHub issue: https://github.com/vlang/v/issues/new/choose

</details>

created time in 12 days

push eventbombsimon/dotfiles

Simon Sawert

commit sha f24574a71a550149136ae31c2090135551379184

Bump oh-my-tmux

view details

Simon Sawert

commit sha 1d0ba2983b9495a92d4f7e838d103b93e26073d8

Add vim plugin

view details

Simon Sawert

commit sha ae3a98a0a08777ef9d3204166159c8d21f63e55c

Better adaption of (oh-my-)zsh

view details

push time in 12 days

Pull request review commentt-tiger/gorm-bulk-insert

Fixed bulkinsert swallowing error from exec

 func insertObjSet(db *gorm.DB, objects []interface{}, excludeColumns ...string) 		strings.Join(placeholders, ", "), 	)) -	return db.Exec(mainScope.SQL, mainScope.SQLVars...).Error+	db = db.Exec(mainScope.SQL, mainScope.SQLVars...)+	return db.Error

Here's a demonstration of the difference (and shows that the result is the same).

EdmundLeex

comment created time in 12 days

Pull request review commentt-tiger/gorm-bulk-insert

Fixed bulkinsert swallowing error from exec

 func insertObjSet(db *gorm.DB, objects []interface{}, excludeColumns ...string) 		strings.Join(placeholders, ", "), 	)) -	return db.Exec(mainScope.SQL, mainScope.SQLVars...).Error+	db = db.Exec(mainScope.SQL, mainScope.SQLVars...)+	return db.Error

How is this any different? Instead of chaining you just assign the result from Exec before calling Error.

Could you give me an example of an error this change solves? To me this is just syntactical changes.

EdmundLeex

comment created time in 12 days

issue commentbombsimon/wsl

Support Output comment last in ExampleTestFunctions

Thank you for the report! Glad you solved this! Please add a new issue if you find any other errors!

suki-fredrik

comment created time in 12 days

startedTerryCavanagh/VVVVVV

started time in 16 days

startedDoctorWkt/acwj

started time in 17 days

push eventdatahax/fail2ban

Simon Sawert

commit sha d5c29510225824124abbfd0dc164326097f37f52

Fix bad datepattern, add test log

view details

Simon Sawert

commit sha 8b0787419b27151b8954a596d2950c490b505711

Add test log for Home Assistant

view details

push time in 18 days

push eventdatahax/fail2ban

Simon Sawert

commit sha 1e4d2326b773586369943b1fc3a79d50b7849977

Fix bad datepattern, add test log

view details

Simon Sawert

commit sha 2e60fcefeb00a9c0a41a3d866d41a9b9d93b71b1

Add test log for Home Assistant

view details

push time in 18 days

push eventdatahax/fail2ban

Simon Sawert

commit sha af183b739a658f96f8d2039758652438febc5eb9

Add Home Assistant filter

view details

Simon Sawert

commit sha afd1f25c229ae3a184a9fff86b88cb0cb8687aeb

Add Unifi filter

view details

push time in 18 days

startedchrislgarry/Apollo-11

started time in 19 days

startedlinuxserver/docker-unifi-controller

started time in 19 days

startedjacobalberty/unifi-docker

started time in 19 days

startedremy/advent-of-code-solved

started time in 22 days

push eventbombsimon/advent-of-code-2019

Simon Sawert

commit sha 8582bf8ae653920f0df8989c7e4fdc5be67d8892

Add Elm implementation for day 1

view details

push time in 23 days

push eventbombsimon/advent-of-code-2019

Simon Sawert

commit sha 7ac6fb34b73ffed6efc8495878b4586f97e4c6a8

Add Elm implementation for day 1

view details

push time in 23 days

push eventbombsimon/advent-of-code-2019

Simon Sawert

commit sha 01fa24d3e795746a04e4cce12e702c03efe6a900

Solution part 1 day 15

view details

Simon Sawert

commit sha a5d37ee2ad6461ac1a70ac952d41e0bc442b04ec

Day 15 part 2 solution

view details

push time in 23 days

startedyeokm1/w31slack

started time in 24 days

push eventbombsimon/advent-of-code-2019

Simon Sawert

commit sha b052822f3cd693c33136df7a8246268c6d838088

Solution for day 14

view details

push time in 24 days

issue commentgolangci/golangci-lint

wsl triggeres on Examples

The ticket states that this was with golangci-lint 1.20.1 but wsl 1.2.5 was merged in 1.20.0. 🤔

However, the somewhat good news is that I cannot reproduce this so I guess it's not a problem.

$ golangci-lint --version
golangci-lint has version 1.22.1 built from da91430 on 2019-12-30T15:46:49Z
$ tail wsl{,_test}.go
==> wsl.go <==
package wsl

import "fmt"

func WSL() {
        fmt.Println("hello")
}

==> wsl_test.go <==
package wsl

func ExampleWSL() {
        WSL()

        // Output: hello
}
go test ./... -v
=== RUN   ExampleWSL
--- PASS: ExampleWSL (0.00s)
PASS
ok      _/home/simon/x   0.009s

$ wsl -w ./... && echo $?
0

$ golangci-lint run --no-config --enable wsl ./... && echo $?
0
freman

comment created time in a month

issue commentgolangci/golangci-lint

wsl triggeres on Examples

This was a bug and fixed in 1.2.5, see this issue. This should be included in the latest version of golangci-lint but I’ll have to double check in a few hours when I’m by my computer.

Either way this should absolutely be allowed and not give a warning!

freman

comment created time in a month

startedsmallstep/certificates

started time in a month

push eventbombsimon/gorm-bulk

Simon Sawert

commit sha 1c2558788f6b885ed777f2b16c55a2e97be53397

Write tests for #5

view details

push time in a month

push eventbombsimon/gorm-bulk

Marlon Pina Tojal

commit sha 9bf070ef4a95ede8a83bf28ed60acdb954eaf62b

fix update created_at (#5) * fix update created_at * fix column name * codestyle

view details

push time in a month

PR merged bombsimon/gorm-bulk

fix update created_at

Fixes #4

+5 -0

0 comment

1 changed file

fnxpt

pr closed time in a month

issue closedbombsimon/gorm-bulk

BulkInsertOnDuplicateKeyUpdate updates CreatedAt

When importing using the function BulkInsertOnDuplicateKeyUpdate, instead of keeping the createdAt value, this value gets updated

closed time in a month

fnxpt

Pull request review commentbombsimon/gorm-bulk

fix update created_at

 func InsertOnDuplicateKeyUpdateFunc(scope *gorm.Scope, columnNames, groups []str 	var duplicateUpdates []string  	for i := range columnNames {-		duplicateUpdates = append(-			duplicateUpdates,-			fmt.Sprintf("%s = VALUES(%s)", columnNames[i], columnNames[i]),-		)+		if columnNames[i] != "`created_at`" {

I would prefer if the happy path was kept to the left both since that's how the rest of the code is written but also because I think it's more readable. It would also be a good idea if there were more special cases in the future.

if columnNames[i] != "`created_at`" {
    continue
}

// Move on and add columnn...
fnxpt

comment created time in a month

startedmvdan/sh

started time in a month

pull request commentfippli/terminal-todo

Description

It seems to be more bugs with the --describe flag as well, there's a problem when there's a description already.

$ cat .todo
[<]You
[>]Test Again :)
[<]This is task

$ todo --task-file .todo --describe
        EDIT DESCRIPTION: XX

$ cat .todo
[<]You
[>]Test Again :)
[<]This is task
[:description]XX

$ todo --task-file .todo --describe
        EDIT DESCRIPTION: YY

$ cat .todo
[<]You
[>]Test Again :)
[<]This is task
[:description]XX
[:description]YY

# XX was pre filled
$ todo --task-file .todo --describe
        EDIT DESCRIPTION: XX YY

$ cat .todo
[<]You
[>]Test Again :)
[<]This is task

[:description]YY
fippli

comment created time in a month

push eventbombsimon/wsl

Florian Brinker

commit sha 9918c28f3f10812b91bec33b18bce42e917f898e

Fix golangci-lint cmd

view details

push time in a month

PR merged bombsimon/wsl

Fix golangci-lint cmd

I've fixed the golangci-lint cmd in the Readme. The previous one threw an error :)

+1 -1

1 comment

1 changed file

fbrinker

pr closed time in a month

push eventbombsimon/advent-of-code-2019

Simon Sawert

commit sha ba6ba90868bce658862fc1d9de0e51675566b06f

Solution for day 13 (animated)

view details

push time in a month

startedpengi/advent_of_code

started time in a month

push eventbombsimon/advent-of-code-2019

Simon Sawert

commit sha 99b2638cc9748acf19faa6d4c94d33d9e2a03cc1

Solution for part 2 day 12

view details

push time in a month

push eventbombsimon/advent-of-code-2019

Simon Sawert

commit sha 243c16de0667f5fba053c67878319f17e400ddf0

Solution for part 1 day 12

view details

Simon Sawert

commit sha 90833d585c7bbeb246b25127897ae5e545032613

Tidy up

view details

push time in a month

startedbetaveros/advent-of-code-golf-2019

started time in a month

push eventbombsimon/advent-of-code-2019

Simon Sawert

commit sha d9fb5ff5979eb58603f2e0963a17916ef6a4402a

Tidy up, don't animate by default

view details

push time in a month

push eventbombsimon/advent-of-code-2019

Simon Sawert

commit sha 859862bab06d7a618143d665d7ea4cd0d37418e9

Solution for part 2 day 10

view details

push time in a month

Pull request review commentfippli/terminal-todo

Import conventions

 # To be able to separate the code into several files after creating a symlink # to ~/bin/todo the path to the source root is good to have. # The relative paths to the project files can now  be used-# like so $lib_dir/someProjectScript.sh+# like so $this_dir/someProjectScript.sh this_path=${BASH_SOURCE[0]}-lib_dir="$(dirname "$this_path")"+this_dir="$(dirname "$this_path")"+this_file="$(basename "$this_path")"+++for src in *.sh; do   +    if [ "$src" = "$this_file" ]; then+        continue+    fi++    [ -f "$src" ] && . "$src"

You have to source the absolute path. If you're not in the repository directory and run the generated script (which runs with absolut path), it won't be able to find the files.

Try [ -f "$this_dir/$src" ] && . "$this_dir/$src"

fippli

comment created time in a month

issue commentfippli/terminal-todo

Idea: Add support for descriptioin of todo

I think yes and no. I would like to have the description This is my super list without having a filename with capital letters and spaces. And also, I would prefer todo super-list instead of todo "This is my super list" if I want to open it quickly. :)

fippli

comment created time in a month

issue commentfippli/terminal-todo

Idea: Management for multiple lists

I chose base64 as encoding (instead of actual hash like md5) to be able to reverse it:

$ for f in test-one another-test final-test; do touch $(echo $f | base64); done
$ ls -l
total 0
-rw-r--r--  1 simon  staff  0 Dec 11 11:32 YW5vdGhlci10ZXN0Cg==
-rw-r--r--  1 simon  staff  0 Dec 11 11:32 ZmluYWwtdGVzdAo=
-rw-r--r--  1 simon  staff  0 Dec 11 11:32 dGVzdC1vbmUK
$ for f in *; do echo $f | base64 -d; done
another-test
final-test
test-one

So yeah, you can just read all the files and decode the base64 encoding :)

Sadly, the bundled base64 binary up until macOS Catalina was an old version requiring the -D flag instead of -d. We could check if base64 supports -d with something like base64 --help | grep -- '-Dd' > /dev/null ($? will be 0 if it does and 1 otherwise).

bombsimon

comment created time in a month

push eventbombsimon/advent-of-code-2019

Simon Sawert

commit sha d319fa7589f7d6c1b824086dc7c68d0d691ff331

Add Go implementation of day 11

view details

push time in a month

push eventbombsimon/advent-of-code-2019

Simon Sawert

commit sha 1c1520fa94a16349886a710289571bb32a11709c

Solution for part 1 day 10

view details

push time in 2 months

startedsalt-die/Advent-of-Code

started time in 2 months

push eventbombsimon/advent-of-code-2019

Simon Sawert

commit sha bec2ab103252581900f79397a01a5dd60a5aac18

Add Elixir implementation for day 4

view details

push time in 2 months

Pull request review commentfippli/terminal-todo

Import conventions

 # like so $lib_dir/someProjectScript.sh this_path=${BASH_SOURCE[0]} lib_dir="$(dirname "$this_path")"- export todo_task_file="${TODO_TASK_FILE:-$lib_dir/.todo}"+export padding="       " todo_header_file="${TODO_HEADER_FILE:-$lib_dir/table_head.sh}" no_local=false # Skip reading of local .todo file -export padding="       "+# Don't know if there is a better way to do this??

. "$this_dir/$src" should probably be something like [ -f "$this_dir/$src" ] && . "$this_dir/$src" to ensure that you're sourcing a file.

fippli

comment created time in 2 months

push eventbombsimon/advent-of-code-2019

Simon Sawert

commit sha 7405b3f0f00ac34b20a19e2913fd17a4c486acb5

Refactor day 9, DRY etc

view details

push time in 2 months

startedjhaals/yopass

started time in 2 months

startedRanddalf/intscript

started time in 2 months

Pull request review commentfippli/terminal-todo

Import conventions

 while test $# -gt 0; do       exit 0       ;;     --this-dir*)

This is actually a boolean flag so this could be --this-dir), but that's my mistake :)

fippli

comment created time in 2 months

Pull request review commentfippli/terminal-todo

Import conventions

 # like so $lib_dir/someProjectScript.sh this_path=${BASH_SOURCE[0]} lib_dir="$(dirname "$this_path")"- export todo_task_file="${TODO_TASK_FILE:-$lib_dir/.todo}"

It doesn't matter but if you set these after you source the file the variable will be available when calling the function without export. Since running a script creates it's own instance of the environment this will be reset after the application exists but I tend to be careful when exporting environment variables to someones shell, that can mess up a lot of things :)

fippli

comment created time in 2 months

Pull request review commentfippli/terminal-todo

Import conventions

 # like so $lib_dir/someProjectScript.sh this_path=${BASH_SOURCE[0]} lib_dir="$(dirname "$this_path")"- export todo_task_file="${TODO_TASK_FILE:-$lib_dir/.todo}"+export padding="       " todo_header_file="${TODO_HEADER_FILE:-$lib_dir/table_head.sh}" no_local=false # Skip reading of local .todo file -export padding="       "+# Don't know if there is a better way to do this??

You can do this in a loop several ways like

this_path=${BASH_SOURCE[0]}
this_dir="$(dirname "$this_path")"
this_file="$(basename "$this_path")"

for src in *.sh; do
    if [ "$src" = "$this_file" ]; then
        continue
    fi

    . "$this_dir/$src"
done

Or

this_path=${BASH_SOURCE[0]}
this_dir="$(dirname "$this_path")"
this_file="$(basename "$this_path")"

for src in $(find . -maxdepth 1 -mindepth 1 -name "*.sh" -a -not -name "$this_file"); do
    . "$this_dir/$src"
done

Or similar.

fippli

comment created time in 2 months

issue commentfippli/terminal-todo

Include other files according to best practices

Yup, just like an import statement! And maybe it's obvious but there should probably don't be any code in the global scope of the sourced files but rather in functions you want to access.

Multiple files can source the same files which might not be necessary but improve readability if two.sh and three.se both uses a function form utils.sh, they should probably be imported in both. :)

bombsimon

comment created time in 2 months

issue openedfippli/terminal-todo

Include other files according to best practices

See How to best include other script?. The shouldn't be executed with bash, there should be a function defined in the related file and after it's been sourced, that function should be called. Example:

$ tail {one,two}.sh
==> one.sh <==
#!/usr/bin/env bash

. two.sh

one_var="this is var"

func_from_two

==> two.sh <==
#!/usr/bin/env bash

func_from_two() {
    echo "This is two with variable from one: '$one_var'"
}
$ ./one.se
This is two with variable from one: 'this is var'

From #25:

I would make all the bash files executable and source the other bash files. By just writing bash you assume that the caller wants to use the first bash in PATH which might not be the case.

Try these:

$ tail -n99 {one,two}.sh ==> one.sh <== #!/usr/bin/env bash

echo "BASH_VERSION in one.sh" echo "$BASH_VERSION" echo ""

echo "Using bash first in PATH" bash two.sh echo ""

echo "Using /bin/bash" /bin/bash two.sh echo ""

echo "Using shebang (/usr/bin/env bash)" /usr/bin/env bash two.sh echo ""

echo "Sourcing second file (keep binary)" . two.sh echo ""

==> two.sh <== #!/usr/bin/env bash

echo "BASH_VERSION in two.sh" echo "$BASH_VERSION" And compare:

/bin/bash one.sh bash one.sh ./one.sh /usr/bin/env bash one.sh Depending on your system and setup you'll get quite different results. You probably want to do the last one and source the other files.

created time in 2 months

push eventbombsimon/advent-of-code-2019

Simon Sawert

commit sha e7f52707dd959f6414be73985c238e601b36ecbe

Solution day 9

view details

push time in 2 months

startedBogdanp/awesome-advent-of-code

started time in 2 months

push eventbombsimon/advent-of-code-2019

Simon Sawert

commit sha 8d47e3f4bf2a1020ea9e64e8591a15a850015d82

Run mix format

view details

push time in 2 months

push eventbombsimon/advent-of-code-2019

Simon Sawert

commit sha 9dc747d80395aa04250e4342431b57a7e38ea298

Add Elixir implementation for part 2, day 3

view details

push time in 2 months

push eventbombsimon/advent-of-code-2019

Simon Sawert

commit sha a70bbc794e6931f1b66301972b2a88d204ba3759

Add Elixir implementation for part 1, day 3

view details

push time in 2 months

Pull request review commentfippli/terminal-todo

Arrow navigation

+#!/usr/bin/env bash++todo_task_file=$1+padding="       "+bold=$(tput bold)+normal=$(tput sgr0)++lines=$( wc -l < "$todo_task_file" )+i=0+echo ""++while [[ $i -lt $((lines)) ]]; do+  i=$((i+1))+  task_line="$( sed "${i}q;d" "$todo_task_file" )"+  task="$(echo $task_line| cut -d']' -f 2)"+  task_status="$(echo $task_line| cut -d']' -f 1)"+  +  if [ "$task_status" = "[>" ]; then+    # The selected task should be bold+    printf "${bold}${padding}%s${normal}\n\n" "$task"  

Sadly, no :(

image

It seems like it's the italic thing that makes it work bad. Without italic:

image

And if I set the color manually to black:

image

The final image has this diff:

diff --git a/read_tasks.sh b/read_tasks.sh
index 34a27c1..118a942 100644
--- a/read_tasks.sh
+++ b/read_tasks.sh
@@ -1,7 +1,6 @@
 #!/usr/bin/env bash
 
-italic="\e[3m"
-normal=$(tput sgr0)
+color="\033[0;30m"
 background_color="\033[46m"
 reset_color="\033[0m"
 
@@ -14,10 +13,10 @@ while [[ $i -lt $((lines)) ]]; do
   task_line="$(sed "${i}q;d" "$todo_task_file")"
   task="$(echo "$task_line"| cut -d']' -f 2)"
   task_status="$(echo "$task_line"| cut -d']' -f 1)"
-  
+
   if [ "$task_status" = "[>" ]; then
     # The selected task should be bold
-    printf "${padding}${italic}${background_color} %s ${normal}${reset_color}\n\n" "$task"  
+    printf "${padding}${color}${background_color} %s ${reset_color}\n\n" "$task"
   else
     # All other tasks should be normal
     printf "${normal}${padding}%s\n\n" "$task"

Sadly I'm not too comfortable with how terminals render these things and what determines the exact output. This post was quite helpful but sadly it doesn't combine color, background color and font style in one line.

fippli

comment created time in 2 months

push eventbombsimon/advent-of-code-2019

Simon Sawert

commit sha 2f8e9ac170b96eaa82f09e9fec04beb627ecfb3a

Solution for part 1 day 8

view details

Simon Sawert

commit sha 268fde0b52f799333aefa415f7cdf93fca14d25d

Solution for part 2 day 8

view details

push time in 2 months

Pull request review commentfippli/terminal-todo

Arrow navigation

+#!/usr/bin/env bash++todo_task_file=$1+padding="       "+bold=$(tput bold)+normal=$(tput sgr0)++lines=$( wc -l < "$todo_task_file" )+i=0+echo ""++while [[ $i -lt $((lines)) ]]; do+  i=$((i+1))+  task_line="$( sed "${i}q;d" "$todo_task_file" )"+  task="$(echo $task_line| cut -d']' -f 2)"+  task_status="$(echo $task_line| cut -d']' -f 1)"+  +  if [ "$task_status" = "[>" ]; then+    # The selected task should be bold+    printf "${bold}${padding}%s${normal}\n\n" "$task"  

Oh, and this is my color palette!

fippli

comment created time in 2 months

Pull request review commentfippli/terminal-todo

Arrow navigation

+#!/usr/bin/env bash++todo_task_file=$1+padding="       "+bold=$(tput bold)+normal=$(tput sgr0)++lines=$( wc -l < "$todo_task_file" )+i=0+echo ""++while [[ $i -lt $((lines)) ]]; do+  i=$((i+1))+  task_line="$( sed "${i}q;d" "$todo_task_file" )"+  task="$(echo $task_line| cut -d']' -f 2)"+  task_status="$(echo $task_line| cut -d']' -f 1)"+  +  if [ "$task_status" = "[>" ]; then+    # The selected task should be bold+    printf "${bold}${padding}%s${normal}\n\n" "$task"  

I'm using iTerm2 with Fira Code.

I'm not sure how you determine colors, I'm not familiar with that way but it doesn't seem to be the default background color: image

I tend to use \[\033[0m\] to reset the default terminal background color. This is from my old bash config before I switched to zsh:

    local NONE="\[\033[0m\]"    # Unsets color to term's fg color

    # Regular colors
    local K="\[\033[0;30m\]"    # Black
    local R="\[\033[0;31m\]"    # Red
    local G="\[\033[0;32m\]"    # Green
    local Y="\[\033[0;33m\]"    # Yellow
    local B="\[\033[0;34m\]"    # Blue
    local M="\[\033[0;35m\]"    # Magenta
    local C="\[\033[0;36m\]"    # Cyan
    local W="\[\033[0;37m\]"    # White

    # Bolded colors
    local EMK="\[\033[1;30m\]"
    local EMR="\[\033[1;31m\]"
    local EMG="\[\033[1;32m\]"
    local EMY="\[\033[1;33m\]"
    local EMB="\[\033[1;34m\]"
    local EMM="\[\033[1;35m\]"
    local EMC="\[\033[1;36m\]"
    local EMW="\[\033[1;37m\]"

    # Background colors
    local BGK="\[\033[40m\]"
    local BGR="\[\033[41m\]"
    local BGG="\[\033[42m\]"
    local BGY="\[\033[43m\]"
    local BGB="\[\033[44m\]"
    local BGM="\[\033[45m\]"
    local BGC="\[\033[46m\]"
    local BGW="\[\033[47m\]"

Could you try to use \[\033[46m\] as background color and reset it with \[\033[0m\]. See how the TODO text is colored for reference.

fippli

comment created time in 2 months

Pull request review commentfippli/terminal-todo

Arrow navigation

+#!/usr/bin/env bash++todo_task_file=$1+padding="       "+bold=$(tput bold)+normal=$(tput sgr0)++lines=$( wc -l < "$todo_task_file" )+i=0+echo ""++while [[ $i -lt $((lines)) ]]; do+  i=$((i+1))+  task_line="$( sed "${i}q;d" "$todo_task_file" )"+  task="$(echo $task_line| cut -d']' -f 2)"+  task_status="$(echo $task_line| cut -d']' -f 1)"+  +  if [ "$task_status" = "[>" ]; then+    # The selected task should be bold+    printf "${bold}${padding}%s${normal}\n\n" "$task"  

Not sure if intentional but I like the fact that this becase a background color in my terminal:

image

fippli

comment created time in 2 months

Pull request review commentfippli/terminal-todo

Arrow navigation

+#!/usr/bin/env bash++todo_task_file=$1+padding="       "+bold=$(tput bold)+normal=$(tput sgr0)++lines=$( wc -l < "$todo_task_file" )+i=0+echo ""++while [[ $i -lt $((lines)) ]]; do+  i=$((i+1))+  task_line="$( sed "${i}q;d" "$todo_task_file" )"+  task="$(echo $task_line| cut -d']' -f 2)"+  task_status="$(echo $task_line| cut -d']' -f 1)"+  +  if [ "$task_status" = "[>" ]; then+    # The selected task should be bold+    printf "${bold}${padding}%s${normal}\n\n" "$task"  

Looks great!

fippli

comment created time in 2 months

Pull request review commentfippli/terminal-todo

Arrow navigation

+#!/usr/bin/env bash++todo_task_file=$1+lines=$( wc -l < "$todo_task_file" )+i=$lines++while ((i > 0)); do+  line_number=$i+  task_line="$( sed "${line_number}q;d" "$todo_task_file" )"+  task_status="$(echo $task_line| cut -d']' -f 1)"+  task_text="$(echo $task_line| cut -d']' -f 2)"++  if [[ "$task_status" == "[>" ]] && ((line_number < lines)); then+    # Unselect the selected line+    unselect_task_update="[<]${task_text}"+    sed -i '' "${line_number} s/.*/${unselect_task_update}/" "$todo_task_file"+    +    # Select the next line+    next_line_number=$((line_number+1))+    next_task_line="$( sed "${next_line_number}q;d" "$todo_task_file" )"+    next_task_text="$(echo $next_task_line| cut -d']' -f 2)"+    select_task_update="[>]${next_task_text}"

If you're at the bottom line and press down you should go to the first line and vice versa. :)

fippli

comment created time in 2 months

more