Skip to content

Instantly share code, notes, and snippets.

View dbrugne's full-sized avatar

Damien Brugne dbrugne

  • Toulouse, France
View GitHub Profile
@dbrugne
dbrugne / test_cors.sh
Created October 27, 2023 13:00
How to test CORS headers with cURL
curl -H "Origin: http://localhost:8080" \
-H "Access-Control-Request-Method: POST" \
-H "Access-Control-Request-Headers: X-Requested-With" \
-X OPTIONS --verbose \
http://localhost:8080/my/api
# ...
# < Access-Control-Allow-Origin: *
# < Access-Control-Allow-Methods: POST
# < Access-Control-Allow-Headers: X-Requested-With
@dbrugne
dbrugne / detect_files_encoding.sh
Created July 21, 2023 07:31
Detect files encoding by CLI
# install dep
npm i -g detect-file-encoding-and-language
# one file
dfeal myfile.txt
# file in folder
find ./myfolder -maxdepth 1 -type f -printf '%p' -exec dfeal {} \;
# recursive
@dbrugne
dbrugne / application.properties
Last active January 11, 2019 17:05
How to log Spring JPA SQL queries and transactions
logging.level.org.hibernate.SQL=debug
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=trace
logging.level.org.springframework.orm.jpa.JpaTransactionManager=debug
@dbrugne
dbrugne / NativeQuery.java
Last active January 4, 2019 08:27
Run a direct SQL native query without JPA repository
package com.innovatm.database;
// ...
@Component
public class NativeQuery {
@Autowired
private JpaTransactionManager jpaTransactionManager;
@dbrugne
dbrugne / itToTestTransform.js
Created June 15, 2017 07:39
jscodeshift to replace it() with test() in .spec.js files
import { parse } from 'path';
/**
* Search it() calls and replace with test() in .spec.js files
*
* Run with: jscodeshift -t itToTestTransform.js lib
*/
module.exports = function (file, api) {
const j = api.jscodeshift;
@dbrugne
dbrugne / depedencyToLocalTransform.js
Created June 14, 2017 08:25
jscodeshift to replace depedencies module import with local module import
import { parse } from 'path';
/**
* Search for
*
* import ... from 'mydependency';
*
* And replace with a relative import:
*
* import ... from '.../mydependency';
@dbrugne
dbrugne / GoogleMapsWithOverlay.html
Last active March 31, 2017 10:38
Google Maps with custom tile server overlay
<!DOCTYPE html>
<html>
<head>
<style>
#map {
height: 430px;
position: relative;
width: 100%;
}
.maps-frame {
@dbrugne
dbrugne / gist:2a62d4dd88f11fa36b75
Last active March 24, 2022 21:50
MongoDB bulk insert from mongoose models
var mongoose = require('mongoose');
var hitSchema = mongoose.Schema({
text: String,
music: String
});
hitSchema.statics.bulkInsert = function(models, fn) {
if (!models || !models.length)
return fn(null);
@dbrugne
dbrugne / gist:a71048fdd422fac3eef9
Created March 26, 2015 10:35
Gandi DNS zone configuration for Mailgun
# The SPF record should be present as TXT to be able to be read by Mailgun, and optionnaly as SPF.
# To do that you need to edit the zone as "expert" cause Gandi IHM refuses to create a second TXT
# record for "@" (it can occurs if you have a Google Webmaster tool verification DNS record)
email 10800 IN CNAME mailgun.org.
krs._domainkey 10800 IN TXT "k=rsa; p=MIG...QAB"
@ 10800 IN SPF "v=spf1 include:mailgun.org ~all"
@ 10800 IN TXT "v=spf1 include:mailgun.org ~all"
@ 10800 IN TXT "google-site-verification=Gy0...xrY"
@dbrugne
dbrugne / gist:b99534a6b6a0cabb740f
Last active August 29, 2015 14:15
Install NodeJS from NVM on MacOS X
# https://academy.appgyver.com/installwizard/steps#/install-nvm
# as regular user (not root)
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | sh
nvm install 0.10
nvm use 0.10
nvm alias default 0.10
node -v