Skip to content

Instantly share code, notes, and snippets.

@alkrauss48
alkrauss48 / SmallCard.js
Created Aug 1, 2022
Small Card Remove Duplication
View SmallCard.js
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 Aug 1, 2022
How to handle rockin power
View HandlePower.js
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 Apr 15, 2022
laravel-interview-scenario
View BlogPostController.php
<?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 Jan 2, 2019
Audo-updating copyright footer using JS
View index.html
<p>
©
<script>document.write(new Date().getFullYear())</script>
<noscript>2019</noscript>
Your Silly Website. All Rights Reserved.
</p>
@alkrauss48
alkrauss48 / inactivity.js
Last active Oct 24, 2017
Pure JS way to handle mouse- and keyboard-inactivity from a user
View inactivity.js
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
View restart_nginx.sh
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 Jun 15, 2022
Running a docker container as a non-root user
View Dockerfile
# 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
View base_table_styles.css
table {
min-width: 100%;
margin-bottom: 2em;
text-align: center;
}
tbody {
border: 2px solid #d1d1d1;
border-right: none;
}
View protoypal_javascript.js
var Person = {
name: '',
init: function(name){
this.name = name;
},
speak: function(){
console.log('My name is ' + this.name);
}
}
@alkrauss48
alkrauss48 / gulpfile.js
Last active Feb 17, 2020
Base gulpfile config for babel, browserify, and uglify - with sourcemaps and livereload
View gulpfile.js
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');