Skip to content

Instantly share code, notes, and snippets.

@oharsta
oharsta / regExp.js
Created June 5, 2024 13:23
JS mail regular expression
const mailRegExp = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.?[a-zA-Z]*$/;
mailRegExp.test("a@a")
// true
mailRegExp.test("a!@a")
// false
mailRegExp.test("a!@a/x")
// false
mailRegExp.test("a_-a@a.x")
// true
@oharsta
oharsta / range.js
Created March 22, 2024 13:43
JS range
const range = (start, end, includeEnd=false) => Array.from({ length: end - start + (includeEnd ? 1 : 0) }, (_, i) => i + start);
@oharsta
oharsta / duplicates.sql
Created August 17, 2023 09:30
Find duplicates based on multiple columns
select s.id, t.*
from service_groups s
join (
select short_name, service_id, count(*) as qty
from service_groups
group by short_name, service_id
having count(*) > 1
) t on s.short_name = t.short_name and s.service_id = t.service_id;
@oharsta
oharsta / index.html
Created February 10, 2022 12:20
Noise example
<css-doodle click-to-update>
<style>
@grid: 80x1 / 80vmin;
@size: @rn(0, 100%, 5);
@offset: @plot(r: .5);
@random(.3) { filter: blur(2px) }
background-size: 35%;
background-image: @svg(
viewBox: 0 0 10 10;
circle {
@oharsta
oharsta / one-two-third-borders.scss
Created January 7, 2021 12:40
1/3 and 2/3 borders of a circle
$width: 70px;
.circle {
display: inline-block;
position: relative;
text-align: center;
width: $width;
height: $width;
margin-right: 20px;
@oharsta
oharsta / IntegrationTest.java
Created November 25, 2020 12:28
Create JWT for Spring Integration test for non-opaque tokens
@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class IntegrationTest {
@LocalServerPort
protected int port;
@Autowired
protected ObjectMapper objectMapper;
@oharsta
oharsta / gist:7a88e3efb91f8749c6e777116a449db8
Created September 13, 2020 07:44
Ensure all annotated indexes on @document models are created in MongoDB after application startup
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.EventListener;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.convert.MappingMongoConverter;
import org.springframework.data.mongodb.core.index.IndexOperations;
import org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver;
import org.springframework.data.mongodb.core.mapping.Document;
@oharsta
oharsta / gist:9312a39f16cfa2ab9094afdc48210c86
Created September 12, 2020 14:20
Open unverified mac app
sudo xattr -r -d com.apple.quarantine /Applications/SomeApp/
@oharsta
oharsta / babel.config.js
Created March 28, 2020 15:56
IE11 Svelte Webpack configuration
module.exports = {
presets: [
[
'@babel/preset-env',
{
debug: true,
"corejs": 3,
"useBuiltIns": "entry",
targets: ['last 2 versions', 'ie >= 11']
}],
@oharsta
oharsta / KeyGenerator.java
Created November 26, 2019 07:53
PEM encoded RSA private key with certificate
package myconext.crypto;
import org.bouncycastle.asn1.x500.X500Name;
import org.bouncycastle.cert.CertIOException;
import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter;
import org.bouncycastle.cert.jcajce.JcaX509v3CertificateBuilder;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.openssl.jcajce.JcaPEMWriter;
import org.bouncycastle.operator.ContentSigner;
import org.bouncycastle.operator.OperatorCreationException;