Posts

Showing posts from May, 2006

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

How To Media Querry For Max Phone Code Example

Example 1: css media query /* BOOSTRAP MEDIA BREAKPOINTS */ /* Small devices (landscape phones, 576px and up) */ @media ( min-width : 576 px ) { .selector { background-color : #f00 ; } } /* Medium devices (tablets, 768px and up) The navbar toggle appears at this breakpoint */ @media ( min-width : 768 px ) { } /* Large devices (desktops, 992px and up) */ @media ( min-width : 992 px ) { } /* Extra large devices (large desktops, 1200px and up) */ @media ( min-width : 1200 px ) { } Example 2: mediaquery for portrate @media ( orientation : portrait ) { body { flex-direction : column ; } }

Css Input Type Selector Code Example

Example 1: how to write css for input type text /* For Example, If we want to change css of "text" type from < input > we do this:*/ input[type=text] { /* Your Code Here */ } Example 2: css attribute selector a[target="_blank"] { background-color: yellow; } /*w3schools*/ Example 3: css set styles for input text input[type="text"] { font-size: 0.9em; padding-top: 0.35rem;}

Android Studio Flutter Build Apk Code Example

Example 1: flutter apk build flutter build apk -- split - per - abi Example 2: flutter build android release apk small flutter build apk -- split - per - abi Example 3: sign flutter app android studio keytool - genkey - v - keystore c : / Users / USER_NAME / key . jks - storetype JKS - keyalg RSA - keysize 2048 - validity 10000 - alias key Example 4: flutter signed apk keytool - genkey - v - keystore ~ / key . jks - keyalg RSA - keysize 2048 - validity 10000 - alias key

C Dynamic Array In C++ Code Example

Example 1: declare dynamic array c++ int main ( ) { int size ; std :: cin >> size ; int * array = new int [ size ] ; delete [ ] array ; return 0 ; } Example 2: how to dynamically allocate an array c++ int * a = NULL ; // Pointer to int, initialize to nothing. int n ; // Size needed for array cin >> n ; // Read in the size a = new int [ n ] ; // Allocate n ints and save ptr in a. for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = 0 ; // Initialize all elements to zero. } . . . // Use a as a normal array delete [ ] a ; // When done, free memory pointed to by a. a = NULL ; // Clear a to prevent using invalid memory reference.

How To Get Array Length In Python 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: find array length python array = [ 1 , 2 , 3 , 4 , 5 ] print ( len ( arr ) )

Cron Job Every Hour Code Example

Example 1: cron job every 10 minutes */10 * * * * will run every 10 min. Example 2: cron job every 10 seconds */10 * * * * * will run every 10 sec.

Convertisseur Youtube Mp3 Code Example

Example: youtube mp3 converter You can use WebTools , it's an addon that gather the most useful and basic tools such as a synonym dictionary , a dictionary , a translator , a youtube convertor , a speedtest and many others ( there are ten of them ) . You can access them in two clics , without having to open a new tab and without having to search for them ! - Chrome Link : https : //chrome.google.com/webstore/detail/webtools/ejnboneedfadhjddmbckhflmpnlcomge/ Firefox link : https : //addons.mozilla.org/fr/firefox/addon/webtools/

Whatsapp Floating-button Codepen Code Example

Example 1: how to add floating whatspp icon < link rel = "stylesheet" href = "https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" > < a href = "https : //api.whatsapp.com/send? phone = 7310747066 & text = Hola % information % . " class = "float" target = "_blank" > < i class = "fa fa-whatsapp my-float" > < / i > < / a > < ! -- CSS -- > < style > . float { position : fixed ; width : 60 px ; height : 60 px ; bottom : 40 px ; right : 40 px ; background - color : # 25 d366 ; color : #FFF ; border - radius : 50 px ; text - align : center ; font - size : 30 px ; box - shadow : 2 px 2 px 3 px # 999 ; z - index : 100 ; } . my - float { margin - top : 16 px ; } < / style > Example 2: floating whatsapp button html < script type = "text/javascript" src = "jquery-3.3.1

Core™ I7-1165G7 Processor Vs. Amd Ryzen 5 4500u Code Example

Example: ryzen 5 vs intel i5 10th gen AMD won by 1 point overall they all are dope

Can Ping IP Address And Nslookup Hostname But Cannot Ping Hostname Temporarily In Windows

Answer : I faced the same problem in my network. When you use this command: ping icecream It uses WINS server since you have used icecream not icecream.my.domain . When looking for such words, Windows looks for NETBIOS names, but when you look for complete domain records, it will look in the DNS server. You can use one of the solutions below: Make sure you have correct records for that station in your WINS server. Use the complete domain name instead of using the host file. E.g. icecream.my.domain You don't have DNS suffixes configured. Either configure them, or use FQDN like this and it should work: ping icecream.my.domain

Can't Upgrade Ubuntu 18.04 To 20.04 Because Of "Please Install All Available Updates For Your Release Before Upgrading" Error

Answer : sequence from 18.04 to 20.04 sudo apt update sudo apt upgrade sudo apt dist-upgrade sudo apt autoremove sudo do-release-upgrade -d -f DistUpgradeViewGtk3 Follow onscreen instruction. Good luck! I was also experiencing the same issue. However, when I ran the usual upgrade commands ( sudo apt upgrade , sudo apt full-upgrade , sudo apt-get dist-upgrade ), they were all reporting that there are no packages to upgrade and no held packages : 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. In the end, I copied the file /usr/bin/do-release-upgrade to my home and modified it as follows: for pkg in upgradable: if 'Phased-Update-Percentage' in pkg.candidate.record: # P-U-P does not exist if it is fully phased continue else: install_count += 1 print(pkg) # <--- ADD THIS LINE # one upgradeable package is enough to stop the dist-upgrade # break # <--- COMMENT THIS LINE OUT This change will print the names of all

Montserrat Black Font Download Code Example

Example: montserrat font <link rel= "preconnect" href= "https://fonts.gstatic.com" > <link href= "https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap" rel= "stylesheet" >

Create A New Workspace In Eclipse

Image
Answer : I use File -> Switch Workspace -> Other... and type in my new workspace name. (EDIT: Added the composite screen shot.) Once in the new workspace, File -> Import... and under General choose "Existing Projects into Workspace. Press the Next button and then Browse for the old projects you would like to import. Check "Copy projects into workspace" to make a copy. In Window->Preferences->General->Startup and Shutdown->Workspaces , make sure that 'Prompt for Workspace on startup' is checked. Then close eclipse and reopen. Then you'll be prompted for a workspace to open. You can create a new workspace from that dialogue. Or File->Switch Workspace->Other... You can create multiple workspaces in Eclipse. You have to just specify the path of the workspace during Eclipse startup. You can even switch workspaces via File→Switch workspace. You can then import project to your workspace, copy paste project to your new workspace folder

How To Find A Bastion Remnant Minecraft Code Example

Example 1: types of bastions minecraft lol no i'm a speedrunner Example 2: types of bastion minecraft hey , are you into modding or something ?

-34f To C Code Example

Example: convert fahrenheit to celsius import java . util . Scanner ; public class Main { public static void main ( String args [ ] ) { Scanner sc = new Scanner ( System . in ) ; int far = sc . nextInt ( ) ; int cel = ( far - 32 ) * 5 / 9 ; System . out . printf ( "%d Fahrenheit is %d Celsius" , far , cel ) ; } }

Programiz.com Online Compiler C++ Code Example

Example 1: c++ online compiler This two are good C ++ compilers : https : //www.onlinegdb.com/online_c++_compiler https : //www.programiz.com/cpp-programming/online-compiler/ Example 2: cpp online compiler Best Site With auto compile : https : //godbolt.org/z/nEo4j7 Example 3: cpp compiler online Three good online compilers : https : //www.onlinegdb.com/online_c++_compiler https : //www.programiz.com/cpp-programming/online-compiler/ http : //cpp.sh/ Example 4: online compiler cpp Good cpp compilers : -- -- -- -- -- -- -- -- -- -- - repl . it / languages / cpp www . w3schools . com / cpp / trycpp . asp ? filename = demo_helloworld onlinegdb . com / online_c ++ _compiler programiz . com / cpp - programming / online - complier cpp . sh

Can I Restore Deleted Files (undo A `git Clean -fdx`)?

Answer : No. Those files are gone. (Just checked on Linux: git clean calls unlink() , and does not backup up anything beforehand.) git clean -fdxn Will do a dry run, and show you what files would be deleted if you ran git clean -fdx (of course this is only helpful if you know this ahead of time, but for next time) IntelliJ/Android Studio allows restoring files from local history.

CSS Input With Width: 100% Goes Outside Parent's Bound

Image
Answer : According to the CSS basic box model, an element's width and height are applied to its content box. Padding falls outside of that content box and increases the element's overall size. As a result, if you set an element with padding to 100% width, its padding will make it wider than 100% of its containing element. In your context, inputs become wider than their parent. You can change the way the box model treats padding and width. Set the box-sizing CSS property to border-box to prevent padding from affecting an element's width or height: border-box : The width and height properties include the padding and border, but not the margin... Note that padding and border will be inside of the box. Note the browser compatibility of box-sizing (IE8+). At the time of this edit, no prefixes are necessary. Paul Irish and Chris Coyier recommend the "inherited" usage below: html { box-sizing: border-box; } *, *:before, *:after { box-sizing: inherit; } For ref

3 Columns Html Code Example

Example 1: html list over three columns ul { -webkit-column-count: 3; -moz-column-count: 3; column-count: 3; } Example 2: how to make three column in a row in html <! DOCTYPE html > < html > < head > < meta name = " viewport " content = " width=device-width, initial-scale=1 " > < style > * { box-sizing : border-box ; } /* Create three equal columns that floats next to each other */ .column { float : left ; width : 33.33 % ; padding : 10 px ; height : 300 px ; /* Should be removed. Only for demonstration */ } /* Clear floats after the columns */ .row :after { content : "" ; display : table ; clear : both ; } </ style > </ head > < body > < h2 > Three Equal Columns </ h2 > < div class = " row " > < div class = " column " style = " background-color : #aaa ; " > < h2 &g