Skip to content

Instantly share code, notes, and snippets.

@alkrauss48
alkrauss48 / soft-delete-duplicate-transactions.sql
Created December 16, 2022 18:57
Soft Deleting duplicate transactions with the help of windowing functions
-- DB: PostgreSQL
-- Soft-delete duplicate transactions made by the same user
-- of the same organization with the same amount within 3 seconds
-- of the last matched transaction
-- The first instance of a match will have a null time_diff, so it
-- will naturally not get included in duplicate_transactions
UPDATE transactions
SET deleted_at = now()
FROM (
@alkrauss48
alkrauss48 / Dockerfile
Last active November 10, 2022 16:24
Running a docker container as a non-root user
# By default, Docker containers run as the root user. This is bad because:
# 1) You're more likely to modify up settings that you shouldn't be
# 2) If an attacker gets access to your container - well, that's bad if they're root.
# Here's how you can run change a Docker container to run as a non-root user
## CREATE APP USER ##
# Create the home directory for the new app user.
RUN mkdir -p /home/app
@alkrauss48
alkrauss48 / SmallCard.js
Created August 1, 2022 03:44
Small Card Remove Duplication
const processData = (event, power) => {
const playerChoice = event.value;
totalCost += playerChoice;
setRockinpower(rockinpower + power);
setPickedList([...pickedList, event.name]);
setWallet(wallet - totalCost);
};
@alkrauss48
alkrauss48 / HandlePower.js
Created August 1, 2022 03:33
How to handle rockin power
const MAX_ROCKIN_POWER = 12;
const MIN_ROCKIN_POWER = 7;
const MAX_PAYOUT = 350;
const MIN_PAYOUT = 20;
const FAILURE_PAYOUT = -50;
useEffect(() => {
let newAmount = wallet;
let message = '';
@alkrauss48
alkrauss48 / BlogPostController.php
Last active April 15, 2022 17:31
laravel-interview-scenario
<?php
public function list_blog_posts(Request $request)
{
$posts = BlogPost::where(
DB::raw("status = '" . $request->input('status') . "'")
)->get();
$posts = $posts->filter(function($value, $key) {
return $value->isPublished();
@alkrauss48
alkrauss48 / functions.php
Created March 2, 2015 17:14
Remove Comments in Wordpress - Completely
<?php
include 'remove-comments.php'
@alkrauss48
alkrauss48 / custom_post_type_cf7_dropdown.php
Last active May 24, 2021 16:50
Adding a custom Wordpress shortcode for building a dynamic dropdown of post type titles with Contact Form 7
wpcf7_add_shortcode('postdropdown', 'createbox', true);
function createbox(){
global $post;
extract( shortcode_atts( array( 'post_type' => 'some_post_type',), $atts ) );
$args = array('post_type' => $post_type );
$myposts = get_posts( $args );
$output = "<select name='postType' id='postType' onchange='document.getElementById(\"postType\").value=this.value;'><option></option>";
foreach ( $myposts as $post ) : setup_postdata($post);
$title = get_the_title();
$output .= "<option value='$title'> $title </option>";
@alkrauss48
alkrauss48 / gulpfile.js
Last active February 17, 2020 12:45
Base gulpfile config for babel, browserify, and uglify - with sourcemaps and livereload
var gulp = require('gulp');
var browserify = require('browserify');
var babelify = require('babelify');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var uglify = require('gulp-uglify');
var sourcemaps = require('gulp-sourcemaps');
var livereload = require('gulp-livereload');
@alkrauss48
alkrauss48 / post_to_google_sheet.gs
Created December 11, 2014 23:05
Use this if you want to read and post to a Google sheet using javascript
// 1. Enter sheet name where data is to be written below
var SHEET_NAME = "Sheet Name";
// 2. Run > setup
//
// 3. Publish > Deploy as web app
// - enter Project Version name and click 'Save New Version'
// - set security level and enable service (most likely execute as 'me' and access 'anyone, even anonymously)
//
// 4. Copy the 'Current web app URL' and post this in your form/script action
@alkrauss48
alkrauss48 / ie_gradients.css
Last active January 30, 2019 21:39
Examples of CSS gradient filters for IE
/* Here's some examples of IE filters for backgrounds with opacity. The first 2 chars of the hex value are the
* opacity values. There are 10 classes to help narrow down which opacity value you might need.
*/
.dark-90 {
background-color: rgba(0, 0, 0, 0.9);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#E6000000,endColorstr=#E6000000);
}
.dark-80 {