Skip to content

Instantly share code, notes, and snippets.

@cetver
cetver / twigjs.js
Created March 24, 2022 14:18
twigjs: needs_context, needs_environment
// twig/factory.js
'use strict';
const Twig = require('twig');
module.exports = function () {
Twig.extend(twig => {
function parseParams(state, params, context) {
if (params) {
@cetver
cetver / rnd.py
Created December 20, 2021 22:52
import random
import collections
population = [1, 2, 3, 4]
weights = [0.5, 0.25, 0.15, 0.1]
samples = random.choices(population, weights, k=100)
print(collections.Counter(samples))
@cetver
cetver / optimize.php
Created April 29, 2020 13:20 — forked from fians/optimize.php
Optimize Image in PHP using Imagick according Google Pagespeed Recommendation
/**
* Optimize image image
*
* https://developers.google.com/speed/docs/insights/OptimizeImages
* -sampling-factor 4:2:0 -strip -quality 85 -interlace JPEG -colorspace sRGB
*
* @access public
* @param string $filePath Path of the file
* @return string Raw image result from the process
*/
@cetver
cetver / git checkout last tag
Last active May 4, 2020 17:05
git checkout last tag
#!/usr/bin/env bash
set -eo pipefail
rep_url="https://github.com/nvm-sh/nvm.git"
last_tag=$(
git ls-remote --tags --quiet --exit-code --refs --sort version:refname "$rep_url" | \
tail --lines 1 | \
sed --regexp-extended 's@.+refs/tags/@@'
)
echo "$last_tag"
@cetver
cetver / install_monaco_font.sh
Created December 30, 2019 00:47 — forked from rogerleite/install_monaco_font.sh
Install Monaco font in Linux
#!/bin/bash
# Install Monaco font in Linux
# Version from nullvideo https://gist.github.com/rogerleite/99819#gistcomment-2799386
sudo mkdir -p /usr/share/fonts/truetype/ttf-monaco && \
sudo wget http://www.gringod.com/wp-upload/software/Fonts/Monaco_Linux.ttf -O - > \
/usr/share/fonts/truetype/ttf-monaco/Monaco_Linux.ttf && \
sudo fc-cache
# Shows local branches without remote
git branch -vv | cut -c 3- | awk '$3 !~/\[/ { print $1 }'
@cetver
cetver / merge-conflict-in-composer.lock
Last active March 2, 2022 17:41
Merge conflict in composer.lock
user@host:/project-dir[master]$ git merge --no-ff DEV-999
Auto-merging composer.lock
CONFLICT (content): Merge conflict in composer.lock
Automatic merge failed; fix conflicts and then commit the result.
user@host:/project-dir[master]$ git reset composer.lock
Unstaged changes after reset:
M composer.lock
user@host:/project-dir[master]$ git checkout -- composer.lock
user@host:/project-dir[master]$ git status
On branch master
@cetver
cetver / recursive_directories_render.php
Last active August 14, 2016 19:29
php recursive directories render
<?php
/**
* @var $splFileInfo SplFileInfo
*/
$root = '/etc/nginx';
$rdi = new RecursiveDirectoryIterator($root, FilesystemIterator::SKIP_DOTS);
$iterator = new RecursiveIteratorIterator($rdi);
//$iterator = new RegexIterator($iterator, '/\.txt/', RegexIterator::MATCH);
$tree = [];
foreach ($iterator as $splFileInfo) {
@cetver
cetver / bash_ansi_format
Last active February 17, 2017 14:24
function for the text coloring/transformation in terminal
#!/bin/bash
#######################################
# Formats a string with ANSI codes
# Arguments:
# $1 the string to be formatted
# FG_* the foreground color, available values
# FG_BLACK
# FG_RED
# FG_GREEN
@cetver
cetver / posgtesql_last_date_of_month.md
Last active August 29, 2015 14:26
posgtesql: last date of month
SELECT (date_trunc('MONTH', now()) + INTERVAL '1 MONTH - 1 day 23:59:59')::timestamp without time zone;