Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Tung Nguyen ntung

🏠
Working from home
View GitHub Profile
@ntung
ntung / dictionary_chunks.py
Created October 24, 2022 21:21 — forked from nz-angel/dictionary_chunks.py
A couple of functions to split a Python dictionary into chunks of equal size
View dictionary_chunks.py
"""
Allows to split a dictionary into chunks of equal size. If the length of the dictionary is not divisible by the chunk
size, the last chunk will be smaller. For example, if the length of the dictionary is 10 and the chunk size is 4,
then we'll have three chunks: two of size 4 and one of size 2.
The first function returns a list with the dictionaries and the second one creates a generator.
"""
def split_dictionary(input_dict, chunk_size):
@ntung
ntung / SitemapController.groovy
Created October 8, 2022 16:25 — forked from itsmeritesh/SitemapController.groovy
Grails controller that automatically generates a sitemapfor your website.
View SitemapController.groovy
/**
* A Sitemap controller that automatically generates sitemap.xml for a grails website.
*
* Be sure to notice the controllerNamesToExclude and actionsToExclude lists
*
* References:
* http://stackoverflow.com/questions/3748125/xml-sitemap-in-grails
* http://stackoverflow.com/questions/2956294/reading-out-all-actions-in-a-grails-controller
*
*/
@ntung
ntung / mac-setup-redis.md
Created October 4, 2022 22:03 — forked from tomysmile/mac-setup-redis.md
Brew install Redis on Mac
View mac-setup-redis.md

type below:

brew update
brew install redis

To have launchd start redis now and restart at login:

brew services start redis
@ntung
ntung / list-of-curl-options.txt
Created June 23, 2022 20:21 — forked from eneko/list-of-curl-options.txt
List of `curl` options
View list-of-curl-options.txt
$ curl --help
Usage: curl [options...] <url>
--abstract-unix-socket <path> Connect via abstract Unix domain socket
--alt-svc <file name> Enable alt-svc with this cache file
--anyauth Pick any authentication method
-a, --append Append to target file when uploading
--basic Use HTTP Basic Authentication
--cacert <file> CA certificate to verify peer against
--capath <dir> CA directory to verify peer against
-E, --cert <certificate[:password]> Client certificate file and password
@ntung
ntung / .gitconfig
Created September 8, 2021 09:28 — forked from johnpolacek/.gitconfig
My current .gitconfig aliases
View .gitconfig
[alias]
co = checkout
cob = checkout -b
coo = !git fetch && git checkout
br = branch
brd = branch -d
brD = branch -D
merged = branch --merged
st = status
aa = add -A .
@ntung
ntung / javafx.md
Created June 25, 2021 21:46 — forked from androidfred/javafx.md
java.lang.ClassNotFoundException: javafx.util.Pair
View javafx.md

java.lang.ClassNotFoundException: javafx.util.Pair happens because javafx.util.Pair and other classes from javafx.util are not included in OpenJDK. Options for resolving:

Switch class

Map.Entry<K, V> from java.util is similar to javafx.util.Pair.

Install java-openjfx

Install java-openjfx through your package manager. (or whatever means you used to install Java on your machine) Note that java-openjfx is compatible with OpenJDK8, not previous versions.

After installing java-openjfx, you may have to add it manually to your IDE SDK classpath. Eg in IntelliJ, you may have to go to Project Structure | SDKs | <select your SDK> | Classpath | + (the Classpath +, not the SDKs +) | and add /usr/lib/jvm/java-8-openjdk/jre/lib/ext/jfxrt.jar (which should be there now that java-openjfx has been installed) | OK

@ntung
ntung / JedisTest.java
Created July 10, 2020 06:00 — forked from FredrikWendt/JedisTest.java
Example usage of Jedis
View JedisTest.java
package se.wendt.statoil.mastercard;
import java.util.ArrayList;
import java.util.concurrent.CountDownLatch;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPubSub;
public class JedisTest {
@ntung
ntung / sync.groovy
Created July 7, 2020 15:37 — forked from pditommaso/sync.groovy
Prevent multiple JVM to access concurrently the same file
View sync.groovy
import java.nio.channels.FileLock
final file = new RandomAccessFile(new File("foo.lock"), "rw")
println "<Entering in critical section>"
try {
/*
* wait to acquire a lock
*/
def secs = 0
FileLock lock
@ntung
ntung / git-log-pretty
Created May 15, 2020 16:22 — forked from miebach/git-log-pretty
pretty git log graph with coloured branches
View git-log-pretty
# Visualizing branch topology in git on the commandline
git log --graph --oneline --full-history --all
git log --graph --full-history --all --pretty=format:"%h%x09%d%x20%s"
# With colors in Bash:
git log --graph --full-history --all --color --pretty=format:"%x1b[31m%h%x09%x1b[32m%d%x1b[0m%x20%s"
@ntung
ntung / kubectl-multi-version-brews.md
Created March 3, 2020 06:18 — forked from rdump/kubectl-multi-version-brews.md
kubectl multi-version brews (kubernetes-cli formula)
View kubectl-multi-version-brews.md

kubectl multi-version brews

We need to run multiple versions of kubectl for compatibility with various kubernetes clusters.

It's a bit easier to get and use multiple versions of kubectl using Homebrew than it is using Macports.

With brew, it's simple to:

  • Install a bunch of versions of kubectl (in the kubernetes-cli Formula)
  • Switch between them as needed