Skip to content

Instantly share code, notes, and snippets.

@grizmio
grizmio / trim.sh
Created November 16, 2021 17:48
Remove last line from really big files
#!/bin/bash
# credits:
# https://stackoverflow.com/a/17794626/16157358
# https://stackoverflow.com/questions/4881930/remove-the-last-line-from-a-file-in-bash
### NOT DONE BY ME, JUST KEEPING FOR POSTERITY
filename="example.txt"
file_size="$(stat --format=%s "$filename")"
trim_count="$(tail -n1 "$filename" | wc -c)"
@grizmio
grizmio / cakephp_find_list_index_0.php
Created September 29, 2021 01:38
cakephp find list 0 index based
<?php
public function search() {
$index = 0;
$xs = $this->Xs->find('list', [
'keyField' => function() use (&$index){
return $index++;
},
'valueField' => function ($e) {
return ['id' => $e->id,
'foo' => $e->foo
@grizmio
grizmio / gist:618079e52cedeeb405f85a3317473ed3
Created September 16, 2021 14:12
svg plus text same vertical alignment
<style>
.col-peco-vertical-center {
display:inline-block;
vertical-align: middle;
}
</style>
<div class="col-peco-vertical-center">
<svg viewBox="0 0 95 90" style="height: 1.5em; fill: #705898">
@grizmio
grizmio / gist:90996af3ee7e31937e2a291218a7c094
Created September 9, 2021 14:39
Installing dropwatch on ubuntu 20.04
For the next error, install libtool
cc -g -Wall -Werror -I/usr/include/libnl3 -I/usr/include/libnl3 -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600 -I/usr/include/readline -g -O2 -lnl-3 -lnl-genl-3 -lnl-3 -lreadline -lpcap -lbfd -o dropwatch main.o lookup.o lookup_kas.o lookup_bfd.o
/usr/bin/ld: main.o: in function `free_netlink_msg':
/home/aneweraofwonder/srcs/dropwatch/src/main.c:254: undefined reference to `nlmsg_free'
/usr/bin/ld: main.o: in function `handle_dm_config_new_msg':
/home/aneweraofwonder/srcs/dropwatch/src/main.c:561: undefined reference to `genlmsg_parse'
/usr/bin/ld: /home/aneweraofwonder/srcs/dropwatch/src/main.c:570: undefined reference to `nla_get_u8'
@grizmio
grizmio / foo.sh
Created May 7, 2021 16:55
Archlinux arm alarm aarch64 raspberry pi 4 fancontrol
# Installing python gpio, fancontrol on archlinux arm 64 bit, aarch64 using yay
yay -S libgpiod
sudo pip install RPi.GPIO2
yay -S raspberrypi-userland-aarch64-git
wget https://raw.githubusercontent.com/vgooz/FanControl/master/fancontrol.py
chmod +x fancontrol.py
sudo fancontrol.py
@grizmio
grizmio / gist:1d1f29796a587b4687d79faa94b96510
Created March 31, 2021 21:42
HOWTO nessus essentials, básico
De la siguiente URL, hay que crear un key/token:
https://es-la.tenable.com/products/nessus/nessus-essentials
Después crear el contenedor:
docker run --name "nessus" -d -p 8834:8834 tenableofficial/nessus
Seguir los pasos de la web:
open "https://127.0.0.1:8834/"
@grizmio
grizmio / C.php
Created December 29, 2020 00:02
Symfony Doctrine jsonb columns postgresql operators with escape ? character since php 7.4
<?php
$v = "foobar.baz";
$rsm = new \Doctrine\ORM\Query\ResultSetMappingBuilder($this->_em);
$rsm->addRootEntityFromClassMetadata(Bazar::class, 't_alias');
$query = $this->_em->createNativeQuery("select * from t td where t.foo ??| :v order by id asc", $rsm);
$query->setParameter("v", $v);
$v = ["asd", "qwert"];
@grizmio
grizmio / gist:5f4b330ea30599a3327f1bea29d0cb02
Created September 22, 2020 17:21
Symfony, Webencore, yarn, /public/build to just /public
'cause Amnesia.
webpack.config.js:
.setOutputPath('public/')
// public path used by the web server to access the output path
.setPublicPath('/')
assets.yaml:
json_manifest_path: '%kernel.project_dir%/public/manifest.json'
@grizmio
grizmio / foo.py
Created July 21, 2020 03:01
pg8000 cursor results as dictionary
import pg8000
# thanks to: Sucas Venior https://stackoverflow.com/questions/58658690/retrieve-query-results-as-dict-in-sqlalchemy
def rows_as_dicts(cursor):
"""convert tuple result to dict with cursor"""
col_names = [i[0].decode() for i in cursor.description]
for row in cursor:
x = dict(zip(col_names, row))
yield x
@grizmio
grizmio / gist:ed689558a1fa8fd879d8e70c69da4c2f
Created April 13, 2020 16:59
Example to wait for postgres container before start another container using docker-compose.yml
# Credits to: https://github.com/peter-evans
# Extracted from: https://github.com/peter-evans/docker-compose-healthcheck/blob/master/docker-compose.yml
# TL;DR;
version: "2.2"
services:
foo:
image: an_image:tag
networks: