Posts

Create Group Linux Command Line Code Example

Example 1: how to create a user and add it to a group in linux useradd -G examplegroup exampleusername Example 2: how to create a new group in linux groupadd [ OPTIONS ] GROUPNAME

Cron To Run Every 30 Minutes Code Example

Example 1: crontab every 30 minutes in specific minute // every 30 minutes */30 * * * * // it depends on the crontab version you are using // example: every 30 minutes at number '5' // mode 1 5,35 * * * * // mode 2 5/30 * * * * Example 2: run cron every 15 minutes */15 * * * *

Creating A Game Board With Tkinter

Answer : I created a board of labels and color them according to which is clicked: import Tkinter as tk board = [ [None]*10 for _ in range(10) ] counter = 0 root = tk.Tk() def on_click(i,j,event): global counter color = "red" if counter%2 else "black" event.widget.config(bg=color) board[i][j] = color counter += 1 for i,row in enumerate(board): for j,column in enumerate(row): L = tk.Label(root,text=' ',bg='grey') L.grid(row=i,column=j) L.bind('<Button-1>',lambda e,i=i,j=j: on_click(i,j,e)) root.mainloop() This doesn't do any validation (to make sure that the element clicked is at the bottom for example). It would also be much better with classes instead of global data, but that's an exercise for the interested coder :). You probably want to create a grid of Buttons. You can style them according to the values in board , and assign a callback that updates the board when clicke...

AndAlso/OrElse In VBA

Answer : The only short circuiting (of a sort) is within Case expression evaluation, so the following ungainly statement does what I think you're asking; Select Case True Case (myObject Is Nothing), Not myObject.test() MsgBox "no instance or test == false" Case Else MsgBox "got instance & test == true" End Select End Sub This is an old question, but this issue is still alive and well. One workaround I've used: Dim success As Boolean ' False by default. If myObj Is Nothing Then ' Object is nothing, success = False already, do nothing. ElseIf Not myObj.test() Then ' Test failed, success = False already, do nothing. Else: success = True ' Object is not nothing and test passed. End If If success Then ' Do stuff... Else ' Do other stuff... End If This basically inverts the logic in the original question, but you get the same result. I think it's a cleaner solution t...

Accessing Kotlin Extension Functions From Java

Answer : All Kotlin functions declared in a file will be compiled by default to static methods in a class within the same package and with a name derived from the Kotlin source file (First letter capitalized and ".kt" extension replaced with the "Kt" suffix). Methods generated for extension functions will have an additional first parameter with the extension function receiver type. Applying it to the original question, Java compiler will see Kotlin source file with the name example.kt package com.test.extensions public fun MyModel.bar(): Int { /* actual code */ } as if the following Java class was declared package com.test.extensions class ExampleKt { public static int bar(MyModel receiver) { /* actual code */ } } As nothing happens with the extended class from the Java point of view, you can't just use dot-syntax to access such methods. But they are still callable as normal Java static methods: import com.test.extensions.ExampleKt; MyMod...

Wordpress - Add A Separator To The Admin Menu?

Answer : Here's a quick and dirty way to get what you want. Background WordPress stores admin menu sections in a global array called $menu . To add a separator you add an element to the $menu array using an index that is between the indexes of the options that you want to separate. Using the add_admin_menu_separator() function So I've written a function to encapsulate the logic for this I called add_admin_menu_separator() . You'll need to pick an array index number that is higher than the option after which you want to add a separator, and then call the function add_admin_menu_separator() passing said index as your parameter. For example: add_admin_menu_separator(37); The add_admin_menu_separator() function itself Here's the definition of the function add_admin_menu_separator() which you can copy into your theme's functions.php file. Yes it is arcane but then so is the code that creates and uses the global $menu array. (Plans are to eventu...

Continue In Loop Python Code Example

Example 1: continue python The continue statement in Python returns the control to the beginning of the while loop . The continue statement rejects all the remaining statements in the current iteration of the loop and moves the control back to the top of the loop . The continue statement can be used in both while and for loops . Example 2: python continue for i in range ( 10 ) : if i == 3 : # skips if i is 3 continue print ( i ) Example 3: continue statement python import numpy as np values = np . arange ( 0 , 10 ) for value in values : if value == 3 : continue elif value == 8 : print ( 'Eight value' ) elif value == 9 : break Example 4: python for continue >>> for num in range ( 2 , 10 ) : . . . if num % 2 == 0 : . . . print ( "Found an even number" , num ) . . . continue . . . print ( "Found a number" , num ) Found an even number 2 Found a number 3 Found an...

Angular Ng Generate Component In Folder Code Example

Example: ng g component ng g class < name > [ options ]

Can I Have Multiple GitHub Actions Workflow Files?

Answer : You can have multiple files in the .github/workflows folder. All files will be read and run as independent tests. The 'on' parameter on each file will tell when it must be called. Following your idea you could have: dev.workflow.yml - To run some kind of testing maybe (only on dev branch, when push) name: Dev Workflow - Test and check thing on: push: branches: - dev jobs: ... prod.workflow.yml - To build and deploy your project (only on master branch, when a PR is closed) name: Master Workflow - Build and deploy to production on: pull_request: types: closed branches: - master jobs: ... Since this question was asked, GitHub has made a few changes to workflows. They are now written in YAML syntax rather than HCL, and instead of being stored in a .github/main.workflow file, they are stored in a .github/workflows directory. The documentation says that "You must store workflow files" (note the plural) "in the .gith...

Compile Time Error Are Static Errors That Can Be Found Where In The Code Code Example

Example: compilation vs runtime error in c A runtime error happens during the running of the program. A compiler error happens when you try to compile the code. If you are unable to compile your code, that is a compiler error. If you compile and run your code, but then it fails during execution, that is runtime.

Android Studio + Volley = NoClassDefFound?

Answer : Exception java.lang.NoClassDefFoundError: com.google.android.gms.common.AccountPicker Found the fix here. Basically, open a command prompt (or terminal) and navigate to your project directory. Use the following command on Windows: For Windows users: gradlew.bat clean And for mac users type: ./gradlew clean Then reload Android Studio and try again!

CSS Grid Layout Not Working In IE11 Even With Prefixes

Answer : IE11 uses an older version of the Grid specification. The properties you are using don't exist in the older grid spec. Using prefixes makes no difference. Here are three problems I see right off the bat. repeat() The repeat() function doesn't exist in the older spec, so it isn't supported by IE11. You need to use the correct syntax, which is covered in another answer to this post, or declare all row and column lengths. Instead of: .grid { display: -ms-grid; display: grid; -ms-grid-columns: repeat( 4, 1fr ); grid-template-columns: repeat( 4, 1fr ); -ms-grid-rows: repeat( 4, 270px ); grid-template-rows: repeat( 4, 270px ); grid-gap: 30px; } Use: .grid { display: -ms-grid; display: grid; -ms-grid-columns: 1fr 1fr 1fr 1fr; /* adjusted */ grid-template-columns: repeat( 4, 1fr ); -ms-grid-rows: 270px 270px 270px 270px; /* adjusted */ grid-template-rows: repeat( 4, 270px ); grid-gap: 30px; } Older spec re...

Check Folder Size In Linux Terminal Code Example

Example 1: check folder sizes linux du - h -- max - depth = 1 Example 2: how to check folder size in linux # show all folder size in the current directory du - h -- max - depth = 1 Example 3: check folder size in linux terminal du - sh / home / user / Example 4: linux find size of directory and subdirectories du - s / home / george Example 5: check directory size du - sh / home / george

Css Flex Stretch Height Code Example

Example: flexbox stretch height . flex - 2 { display : flex ; align - items : stretch ; }

Python Array Size Code Example

Example 1: size array python size = len ( myList ) Example 2: python get array length # To get the length of a Python array , use 'len()' a = arr . array ( ‘d’ , [ 1.1 , 2.1 , 3.1 ] ) len ( a ) # Output : 3 Example 3: python array length len ( my_array ) Example 4: find array length in python a = arr . array ( 'd' , [ 1.1 , 2.1 , 3.1 ] ) len ( a )

Create Telegram Bot In Python Using Telethon

Answer : Telegram is a popular messaging application. This library is meant to make it easy for you to write Python programs that can interact with Telegram. Think of it as a wrapper that has already done the heavy job for you, so you can focus on developing an application. If you are the owner of the Telegram channel/group, you can use BotFather to create a bot. However, if you are not the admin of the channel/group, you can use Telethon to create Telegram bot Telethon is an asyncio Python 3 MTProto library to interact with Telegram's API as a user or through a bot account (bot API alternative). Install Telethon # The first thing is install Telethon pip install telethon Create Application # Before working with Telegram’s API, you need to get your own API ID and hash: Login to your Telegram account with ...