Skip to content

Instantly share code, notes, and snippets.

@apieceofbart
apieceofbart / test.js
Last active January 18, 2024 17:14
Async testing with jest fake timers and promises
PLEASE CHECK THIS REPO WITH THE EXAMPLES THAT YOU CAN RUN:
https://github.com/apieceofbart/async-testing-with-jest-fake-timers-and-promises
// Let's say you have a function that does some async operation inside setTimeout (think of polling for data)
function runInterval(callback, interval = 1000) {
setInterval(async () => {
const results = await Promise.resolve(42) // this might fetch some data from server
callback(results)
}, interval)
@PasanBhanu
PasanBhanu / CheckNetwork.java
Last active July 25, 2023 13:28
Check Internet Connection in Android (API Level 29) Using Network Callback
/*
You need to call the below method once. It register the callback and fire it when there is a change in network state.
Here I used a Global Static Variable, So I can use it to access the network state in anyware of the application.
*/
// You need to pass the context when creating the class
public CheckNetwork(Context context) {
this.context = context;
}
@karlhadwen
karlhadwen / cloudSettings
Last active December 6, 2022 09:03
VSCode Settings
{"lastUpload":"2020-12-31T16:16:14.406Z","extensionVersion":"v3.4.3"}
@karlhadwen
karlhadwen / .zshrc
Last active April 12, 2024 01:56
.zshrc settings
export ZSH="/Users/karlhadwen/.oh-my-zsh"
export PATH=${PATH}:/usr/local/mysql/bin/
ZSH_THEME="robbyrussell"
ZSH_DISABLE_COMPFIX=true
plugins=(
git
zsh-autosuggestions
last-working-dir
@stepney141
stepney141 / BookmarkAPI_en.md
Last active April 4, 2023 01:45
(DEPRECATED) Twitter Undocumented Endpoints for Bookmark

Cheatsheet for Django QuerySets

Current Django Version: 2.2

Methods that return new QuerySets

Can be chained:

Entry.objects.filter(**kwargs).exclude(**kwargs).order_by(**kwargs)
@youonf
youonf / google_colab_drive_mount.py
Last active April 11, 2021 00:28
Mounting Google Drive to Google Colab Notebook
from google.colab import drive
drive.mount('/content/gdrive')
root_path = 'gdrive/My Drive/your_project_folder/' #change dir to your project folder
@vanushwashere
vanushwashere / README.md
Last active April 18, 2024 03:14
Systemd unit file for supervisord service

Systemd unit file for supervisord service

  • place this config in /etc/systemd/system/supervisord.service
  • kill all supervisord processes
  • sudo systemctl daemon-reload
  • sudo systemctl enable supervisord
  • start with sudo systemctl start supervisord if already not started
@amrynsky
amrynsky / gist:eef394e7a8a15bf2412c36943dea76a1
Last active August 25, 2022 16:45
Change default java version

First run /usr/libexec/java_home -V which will output something like the following:

Matching Java Virtual Machines (5):
    11, x86_64:	"OpenJDK 11"	/Library/Java/JavaVirtualMachines/openjdk-11.jdk/Contents/Home
    10.0.2, x86_64:	"Java SE 10.0.2"	/Library/Java/JavaVirtualMachines/jdk-10.0.2.jdk/Contents/Home
    9.0.4, x86_64:	"Java SE 9.0.4"	/Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home
    1.8.0_152, x86_64:	"Java SE 8"	/Library/Java/JavaVirtualMachines/jdk1.8.0_152.jdk/Contents/Home
    1.8.0_111, x86_64:	"Java SE 8"	/Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home
@JamieMason
JamieMason / group-objects-by-property.md
Created September 14, 2018 07:38
Group Array of JavaScript Objects by Key or Property Value

Group Array of JavaScript Objects by Key or Property Value

Implementation

const groupBy = key => array =>
  array.reduce((objectsByKeyValue, obj) => {
    const value = obj[key];
    objectsByKeyValue[value] = (objectsByKeyValue[value] || []).concat(obj);
    return objectsByKeyValue;