Skip to content

Instantly share code, notes, and snippets.

@dmdboi
dmdboi / View.ts
Created December 5, 2023 20:59
Adonis 5 - Markdown renderer
import View from '@ioc:Adonis/Core/View'
import showdown from 'showdown'
/*
|--------------------------------------------------------------------------
| Preloaded File
|--------------------------------------------------------------------------
|
| Any code written inside this file will be executed during the application
| boot.
@thetutlage
thetutlage / story.md
Created May 6, 2023 06:25
HTML forms and surprises

HTML forms and surprises

If you are using Rails, Laravel, or AdonisJS (the only one's I know), then these inconsistencies are handled automatically for you.

HTML forms have particular serializing behavior attached to them that you need to understand and address to work with normalized data in your applications.

I see a few talking about it because we stopped using HTML forms with the rise of frontend frameworks. However, they are now returning to HTML forms, so I expect more developers to encounter these surprises.

Empty fields lead to empty strings

@bsdelf
bsdelf / yarn-list.js
Last active June 7, 2023 12:55
yarn list direct dependencies with locked version
const path = require('path');
const exec = require('child_process').exec;
function run(command) {
return new Promise((resolve, reject) => {
exec(command, function (error, stdout, stderr) {
if (error) {
reject(error);
} else {
resolve(stdout);
@nateberkopec
nateberkopec / correction.md
Last active February 14, 2024 16:22
A Simple Correction

In yesterday's post I said, in relation to "how does .present? work on ActiveRecord::Relation", I said that present? performs an existence check SELECT 1 AS one FROM ... LIMIT 1 because it calls exists? underneath. This is actually wrong - it loads the relation.

Jonathan Mast corrected me on Twitter. It turns out, I should have paid closer attention! Here is the actual implementation of blank? on ActiveRecord::Relation on Rails master:

# Returns true if relation is blank.
def blank?
  records.blank?
end
@yidas
yidas / js-nl2br-br2nl.md
Last active September 29, 2023 05:26
JavaScript nl2br & br2nl functions

JavaScript nl2br & br2nl functions

The exchange of new line & br HTML tag could refer to PHP - nl2br() function, which uses to inserts HTML line breaks before all newlines in a string.

These JavaScript functions consider whether to use insert or replace to handle the swap.

nl2br

@mrmartineau
mrmartineau / stimulus.md
Last active May 12, 2024 04:35
Stimulus cheatsheet
@jaysalvat
jaysalvat / npm-outdated.js
Created February 17, 2017 16:03
Check NPM for outdated dependencies and output a package.json friendly JSON.
'use strict';
let exec = require('child_process').exec;
exec('npm outdated --json', (err, stdout, sdterr) => {
if (!stdout) {
process.exit();
}
let json = JSON.parse(stdout),
@andrewlimaza
andrewlimaza / honeypot-example.php
Last active October 5, 2023 04:20
Simple honeypot for an HTML form using PHP
<?php
//check if form was sent
if($_POST){
$to = 'some@email.com';
$subject = 'Testing HoneyPot';
$header = "From: $name <$name>";
$name = $_POST['name'];
@mlynch
mlynch / info.plist
Last active August 6, 2023 07:31
Disable App Transport Security in iOS 9
<!--
This disables app transport security and allows non-HTTPS requests.
Note: it is not recommended to use non-HTTPS requests for sensitive data. A better
approach is to fix the non-secure resources. However, this patch will work in a pinch.
To apply the fix in your Ionic/Cordova app, edit the file located here:
platforms/ios/MyApp/MyApp-Info.plist
And add this XML right before the end of the file inside of the last </dict> entry:
@marcelweder
marcelweder / wp-filter-interlaced.php
Last active December 22, 2016 16:29
WordPress image interlace filter
<?php
/**
* This workaround append interlaced (aka progressive) on images
* https://korrekt.ch/
* We salute you ;)
*/
add_filter('wp_generate_attachment_metadata', 'korrekt_wp_generate_attachment_metadata', 99, 2);
function korrekt_wp_generate_attachment_metadata($metadata, $attachment_id)
{
if (!function_exists('imageinterlace'))