Skip to content

Instantly share code, notes, and snippets.

@ph3b
ph3b / zod-itty-router-middleware.ts
Last active April 5, 2024 21:11
itty-router + zod query validation
import { RequestHandler, IRequest, json } from "itty-router";
import { z } from "zod";
export const zodQuery =
<T extends z.ZodRawShape>(
rawShape: T
): RequestHandler<
IRequest & { data: z.infer<z.ZodObject<typeof rawShape>> }
> =>
(request) => {
@ph3b
ph3b / _spacing-helpers.scss
Created July 11, 2018 21:39 — forked from jacurtis/_spacing-helpers.scss
SASS Margin and Padding Helpers Loop. Generates .m-t-10 type helper classes.
/*
This .scss loop will create "margin helpers" and "padding helpers" for use in your web projects.
It will generate several classes such as:
.m-r-10 which gives margin-right 10 pixels.
.m-r-15 gives MARGIN to the RIGHT 15 pixels.
.m-t-15 gives MARGIN to the TOP 15 pixels and so on.
.p-b-5 gives PADDING to the BOTTOM of 5 pixels
.p-l-40 gives PADDING to the LEFT of 40 pixels
@ph3b
ph3b / LSTM_Binary.py
Created January 30, 2018 18:21 — forked from urigoren/LSTM_Binary.py
LSTM Binary classification with Keras
from keras.layers import Dense, Dropout, LSTM, Embedding
from keras.preprocessing.sequence import pad_sequences
from keras.models import Sequential
import pandas as pd
import numpy as np
input_file = 'input.csv'
def load_data(test_split = 0.2):
print ('Loading data...')
@ph3b
ph3b / example_group_create_or_update_request.json
Last active March 19, 2023 13:54
DRF - ManyToMany, intermediate model and custom save/update
// Assumes members already exist with id 1 and 2.
{
"name": "My group 1",
"members": [
{ "id": 1, "role": "Leader" },
{ "id": 2, "role": "Regular" }
]
}
@ph3b
ph3b / solving_spark_signature_error.md
Created March 29, 2017 21:40 — forked from hkhamm/solving_spark_signature_error.md
Solving a Spark Invalid signature file digest for Manifest main attributes error

##Solving a Spark error: Invalid signature file digest for Manifest main attributes

When using spark-submit to run a jar, you may encounter this error:

Invalid signature file digest for Manifest main attributes

The error occurs when one of the included libraries in the jar's META-INF directory has a bad signature.

@ph3b
ph3b / crypto-ctr.js
Created November 17, 2016 20:04 — forked from chris-rock/crypto-ctr.js
Encrypt and decrypt text in nodejs
// Part of https://github.com/chris-rock/node-crypto-examples
// Nodejs encryption with CTR
var crypto = require('crypto'),
algorithm = 'aes-256-ctr',
password = 'd6F3Efeq';
function encrypt(text){
var cipher = crypto.createCipher(algorithm,password)
var crypted = cipher.update(text,'utf8','hex')
@ph3b
ph3b / post-receive
Created October 18, 2016 22:33 — forked from tlrobinson/post-receive
Super simple git post-receive hook for Node.js + nvm + npm + node-foreman + init (Ubuntu) deployment
#!/usr/bin/env bash
set -u
set -e
export GIT_WORK_TREE="/var/www/example.com"
export NODE_VERSION="0.10"
echo "--> Checking out..."
git checkout -f
@ph3b
ph3b / Buffer Overflow Tutorial in Kali.md
Created October 6, 2016 14:08 — forked from apolloclark/Buffer Overflow Tutorial in Kali.md
Buffer overflow demonstration in Kali Linux, based on the Computerphile video
@ph3b
ph3b / restful.js
Created August 31, 2016 14:58 — forked from BinaryMuse/restful.js
Express API with Async/Await
import express from "express";
/**
* Takes a route handling function and returns a function
* that wraps it after first checking that the strings in
* `reserved` are not part of `req.body`. Used for ensuring
* create and update requests do not overwrite server-generated
* values.
*/
function checkReservedParams(routeHandler, ...reserved) {
On remote:
1. $ git init --bare
2. $ touch ./hooks/post-receive
3. $ chmod +x ./hooks/post-receive
4. $ sudo nano ./hooks/post-receive
Paste
```
#!/bin/bash
echo "Hello :) "
git --work-tree=/home/username/var/www/domain.com --git-dir=/home/username/repo/domain.git checkout -f