Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mike-lawrence
mike-lawrence / helper_functions.r
Last active April 23, 2024 13:03
Stan vs LME4 for hiearchical within-subjects designs with binomial outcomes
#' Installs any packages not already installed
#' @examples
#' \dontrun{
#' install_if_missing(c('tidyverse','github.com/stan-dev/cmdstanr'))
#' }
install_if_missing = function(pkgs){
missing_pkgs = NULL
for(this_pkg in pkgs){
@ZucchiniZe
ZucchiniZe / list-files-in-dir.clj
Created February 15, 2016 10:00
simple clojure function to recursively list files in directories.
(let [directory (clojure.java.io/file "/path/to/list")
dir? #(.isDirectory %)]
(map #(.getPath %)
(filter (comp not dir?)
(tree-seq dir? #(.listFiles %) directory))))
@luismts
luismts / GitCommitBestPractices.md
Last active April 23, 2024 13:02
Git Tips and Git Commit Best Practices

Git Commit Best Practices

Basic Rules

Commit Related Changes

A commit should be a wrapper for related changes. For example, fixing two different bugs should produce two separate commits. Small commits make it easier for other developers to understand the changes and roll them back if something went wrong. With tools like the staging area and the ability to stage only parts of a file, Git makes it easy to create very granular commits.

Commit Often

Committing often keeps your commits small and, again, helps you commit only related changes. Moreover, it allows you to share your code more frequently with others. That way it‘s easier for everyone to integrate changes regularly and avoid having merge conflicts. Having large commits and sharing them infrequently, in contrast, makes it hard to solve conflicts.

@alexbruno
alexbruno / valid.cnpj.ts
Last active April 23, 2024 13:02
Validação de CNPJ
// Regex para validação de string no formato CNPJ
export const regexCNPJ = /^\d{2}.\d{3}.\d{3}\/\d{4}-\d{2}$/
// Método de validação
// Referência: https://pt.wikipedia.org/wiki/Cadastro_Nacional_da_Pessoa_Jur%C3%ADdica
export function validCNPJ(value: string | number | number[] = '') {
if (!value) return false
// Aceita receber o valor como string, número ou array com todos os dígitos
const isString = typeof value === 'string'
@xgp
xgp / Dockerfile
Last active April 23, 2024 13:01
Keycloak 17 example using JGroups JDBC_PING discovery protocol for Infinispan
FROM quay.io/keycloak/keycloak:17.0.0 as builder
ENV KC_METRICS_ENABLED=true
ENV KC_FEATURES=preview
ENV KC_DB=postgres
ENV KC_HTTP_RELATIVE_PATH=/auth
# specify the custom cache config file here
ENV KC_CACHE_CONFIG_FILE=cache-ispn-jdbc-ping.xml
# copy the custom cache config file into the keycloak conf dir
@Immolare
Immolare / merge-zip-files-to-folder-script.php
Last active April 23, 2024 13:01
Merge files from zip archive to a destination folder
const ZIP_FILEPATH = '/path';
const ZIP_FILENAME = 'archive.zip';
const ZIP_SUBDIRNAME = 'subdir'; // Folder inside archive
const ZIP_MAINDIRNAME = "maindir"; // Target folder containing files
/* If small archive folder use PHP. Note, on some big archives it doesn't extract all subfolders and files */
function mergeFromZipPHP()
{
$zip = new ZipArchive; // need to be isntalled on server
$zipPath = self::ZIP_FILEPATH.'/'.self::ZIP_FILENAME;
@jamesrochabrun
jamesrochabrun / PHAsset+Extension.swift
Created May 6, 2018 05:25
PHAsset extension that returns an array of assets in a time period related to an asset.
extension PHAsset {
// MARK: This returns an array of alternate assets from a PHAsset
func getAlternatePhotos() -> [PHAsset] {
/// get the collection of the asset to avoid fetching all photos in the library
let collectionFetchResult = PHAssetCollection.fetchAssetCollectionsContaining(self, with: .moment, options: nil)
let options = PHFetchOptions()
options.sortDescriptors = [NSSortDescriptor.init(key: "creationDate", ascending: true)]
@joaohcrangel
joaohcrangel / validation-cpf.ts
Last active April 23, 2024 12:55
Função para validar CPF em TypeScript
function isValidCPF(value: string) {
if (typeof value !== 'string') {
return false;
}
value = value.replace(/[^\d]+/g, '');
if (value.length !== 11 || !!value.match(/(\d)\1{10}/)) {
return false;
}
@KevinBatdorf
KevinBatdorf / check-steam-owned-games-on-humble-bundle.js
Last active April 23, 2024 12:52
Check on HumbleBundle whether you own the game on Steam already
// ==UserScript==
// @name Steam Owned HumbleBundle Games
// @namespace kevinbatdorf
// @version 0.1
// @description Will check whether you own the humble bundle game in your steam library already
// @author You
// @match https://www.humblebundle.com/*
// @icon https://www.google.com/s2/favicons?domain=humblebundle.com
// @grant none
// ==/UserScript==
@zeux
zeux / gctracker.lua
Last active April 23, 2024 12:52
GC tracker for Luau that provides more predicatable (compared to `__gc`...) destructor invocation for dead objects. Supports ~constant time update cost by limiting the iteration count such that update can be called every frame with a small n for negligible performance cost.
--!strict
--[[
BSD Zero Clause License
Copyright (c) 2022 Arseny Kapoulkine
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.