Skip to content

Instantly share code, notes, and snippets.

View fideloper's full-sized avatar
🏠
Working from home

Chris Fidao fideloper

🏠
Working from home
View GitHub Profile
@kljensen
kljensen / mongoose-encrypted-schematype-field.md
Last active June 6, 2023 13:25
Encrypt a text field in Mongoose MongoDB ORM

Encrypting text fields in Mongoose is easy using Node's built-in crypto module. You might want to do this if you're using MongoDB as a service (see the recent MongoHQ security breach); or, if you're storing OAuth tokens that could, in the wrong hands, screw with somebody's account on a 3rd party service. (Of course, you should never encrypt passwords: those should be hashed.)

Imagine you have a Mongoose model like that shown below, which is modified only slighly from the example on the MongooseJS homepage.

var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/test');

var User = mongoose.model('User', {
 name: String,
@alexbilbie
alexbilbie / Caddyfile
Created January 7, 2016 15:29
PHP-FPM Caddyfile example
root /app/public
tls /app/_docker/caddy/server.crt /app/_docker/caddy/server.key
fastcgi / php:9000 php
errors visible
rewrite {
regexp .*
ext /
to /index.php?{query}
}
for bucket in $(aws s3api list-buckets --query 'Buckets[*].{Name:Name}' --output text)
do
echo "$bucket:"
region=$(aws s3api get-bucket-location --bucket $bucket --query 'LocationConstraint' --output text | awk '{sub(/None/,"eu-west-1")}; 1')
parts=$(aws s3api list-multipart-uploads --bucket $bucket --region $region --query 'Uploads[*].{Key:Key,UploadId:UploadId}' --output text)
if [ "$parts" != "None" ]; then
IFS=$'\n'
@matthiasr
matthiasr / delete-s3.sh
Created December 14, 2020 09:18
Delete everything in an S3 bucket (in a hurry)
# I needed to delete ~300k objects from an S3 bucket in a hurry. The better and cheaper solution is to use a lifecycle rule, but those can take a day or two to take effect.
bucket="i-want-to-lose-all-my-data"
mkdir -p deletes
# 1. List all the objects in the bucket, transform them 1000 at a time into request objects for DeleteObjects, write each to a separate file
aws s3api list-objects-v2 --bucket "${bucket}" \
| jq -c '.Contents | _nwise(1000) | map({ Key: .Key }) | { Objects: ., Quiet: true }' \
| awk '{ f = "deletes/" NR ".json"; print $0 > f; close(f) }'
@JeffreyWay
JeffreyWay / gist:1525217
Created December 27, 2011 21:29
Instant Server for Current Directory
alias server='open http://localhost:8000 && python -m SimpleHTTPServer'
server {
listen 80;
listen [::]:80;
server_name site.com;
root /home/forge/site.com;
# FORGE SSL (DO NOT REMOVE!)
# ssl on;
# ssl_certificate;
# ssl_certificate_key;
@kapv89
kapv89 / query-logger.php
Last active January 8, 2019 15:21
Log Queries in L4
<?php
Event::listen('illuminate.query', function($query, $bindings, $time) {
static $count;
if(App::make('env') === 'local')
{
$logFile = __DIR__.'/../storage/logs/queries';
ob_start();
var_dump($bindings, $query);
$str = ob_get_clean();
if($count === null)
@mpstenson
mpstenson / Resize_Column_Based_On_Content.sql
Created August 31, 2016 15:52
Resize Column Based On Content (for mysql
SET @column_name = 'Custom2';
select @column_name;
SET @width_query = CONCAT('SET @max_width = (SELECT CHAR_LENGTH(' , @column_name , ') AS mlen FROM `HS_Request` ORDER BY mlen DESC LIMIT 1)+10;');
PREPARE stmt FROM @width_query;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET @query = CONCAT('ALTER TABLE HS_Request MODIFY ', @column_name, ' VARCHAR(', @max_width, ');');
PREPARE stmt FROM @query;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
@EpocSquadron
EpocSquadron / .gitconfig
Created April 5, 2013 16:10
My global git config
[core]
# Don't track permissions other than standard modes.
filemode = false
# Don't ignore File -> file changes.
ignorecase = false
# Vim is better.
editor = vim
[color]
ui = true
[help]
@NoodlesNZ
NoodlesNZ / Jenkinsfile
Created April 11, 2017 23:08
PHP Pipeline
pipeline {
agent any
stages {
stage('Checkout') {
steps {
checkout scm
sh 'rm -rf build/{logs,pdepend}'