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 / 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 / index.html
Last active January 2, 2019 18:00
Audo-updating copyright footer using JS
<p>
©
<script>document.write(new Date().getFullYear())</script>
<noscript>2019</noscript>
Your Silly Website. All Rights Reserved.
</p>
@alkrauss48
alkrauss48 / inactivity.js
Last active October 24, 2017 17:53
Pure JS way to handle mouse- and keyboard-inactivity from a user
var inactivityTime = function () {
var t;
window.onload = resetTimer;
// DOM Events
document.onmousemove = resetTimer;
document.onkeypress = resetTimer;
function inactivityLogout() {
// optional - turn off the event handlers
// useful for single page apps
@alkrauss48
alkrauss48 / restart_nginx.sh
Created March 29, 2017 14:05
Restart Nginx
restart_nginx () {
# path to pgrep command
PGREP="/usr/bin/pgrep"
# Httpd daemon name,
HTTPD="nginx"
# find httpd pid
$PGREP ${HTTPD}
@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 / base_table_styles.css
Created September 21, 2016 20:57
Base Table Styles
table {
min-width: 100%;
margin-bottom: 2em;
text-align: center;
}
tbody {
border: 2px solid #d1d1d1;
border-right: none;
}
var Person = {
name: '',
init: function(name){
this.name = name;
},
speak: function(){
console.log('My name is ' + this.name);
}
}