Skip to content

Instantly share code, notes, and snippets.

View butsjoh's full-sized avatar

Buts Johan butsjoh

  • Younited
  • Belgium
View GitHub Profile
#!/usr/bin/env bash
# User must be root
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
return
fi
# Check if www-data do exist
q=$(id -u www-data)
@matthewhartman
matthewhartman / install-fonts.txt
Created March 1, 2015 11:27
Install TTF Fonts in Debian
cd fonts
mv *.ttf /usr/share/fonts/truetype
cd /usr/share/fonts/truetype
mkfontscale
mkfontdir
fc-cache
xset fp rehash
@magnetikonline
magnetikonline / README.md
Last active January 14, 2018 03:39
Enable execute of bash scripts on a partition mounted with noexec.

Enable execute on partition mounted with noexec

The example situation:

  • Wish to execute a bash script at /var/foobah/myscript.sh
  • But /var/ has been mounted using noexec via /etc/fstab.
  • How to solve? Using bind mounts.

Firstly, create a directory to hold script(s), located somewhere that has exec rights, then create the target directory on noexec partition:

$ mkdir --parents /opt/magnetik/foobah
require 'date'
class FirebasePush
PUSH_CHARS = '-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz'
def initialize
@prev_ts = 0
@rand_chars = Array.new(12)
end
@mikelehen
mikelehen / generate-pushid.js
Created February 11, 2015 17:34
JavaScript code for generating Firebase Push IDs
/**
* Fancy ID generator that creates 20-character string identifiers with the following properties:
*
* 1. They're based on timestamp so that they sort *after* any existing ids.
* 2. They contain 72-bits of random data after the timestamp so that IDs won't collide with other clients' IDs.
* 3. They sort *lexicographically* (so the timestamp is converted to characters that will sort properly).
* 4. They're monotonically increasing. Even if you generate more than one in the same timestamp, the
* latter ones will sort after the former ones. We do this by using the previous random bits
* but "incrementing" them by 1 (only in the case of a timestamp collision).
*/
@brianstorti
brianstorti / priority_queue.rb
Last active November 17, 2022 16:14
Priority queue implementation in Ruby
class PriorityQueue
attr_reader :elements
def initialize
@elements = [nil]
end
def <<(element)
@elements << element
bubble_up(@elements.size - 1)
@reidmorrison
reidmorrison / my_app
Created January 27, 2015 18:49
Puma Redhat/CentOS startup shell script
#!/bin/bash
# puma - Generic Red Hat Startup script for Puma
# chkconfig: 35 95 05
# description: Generic Puma Startup Script
# processname: puma
# config: /etc/'filename'.conf
# pidfile: /var/run/puma/'filename'.pid
@bendc
bendc / nodelist-iteration.js
Created January 13, 2015 14:39
ES6: Iterating over a NodeList
var elements = document.querySelectorAll("div"),
callback = (el) => { console.log(el); };
// Spread operator
[...elements].forEach(callback);
// Array.from()
Array.from(elements).forEach(callback);
// for...of statement
@edariedl
edariedl / gist:a1c35eb68aebdf41876c
Last active May 7, 2024 08:30
Bulk delete of documents from Elasticsearch in Ruby on Rails

Bulk delete of documents from Elasticsearch in Ruby on Rails

When someone deletes his account we need to delete data from the elasticsearch. All account data are removed by bulk SQL query but elasticsearch-model cannot be notified to destroy related elasticsearch documents. I had to find out how to do it. It had to be done in the background job otherwise it could take too long.

After looking around in the source code of elasticsearch ruby gems, Elastcisearch API and with a little help from Karmi (author of elasticsearch gems) I found a solution. It consists of the following three things.

@JunichiIto
JunichiIto / alias_matchers.md
Last active May 9, 2025 08:50
List of alias matchers in RSpec 3

This list is based on aliases_spec.rb.

You can see also Module: RSpec::Matchers API.

matcher aliased to description
a_truthy_value be_truthy a truthy value
a_falsey_value be_falsey a falsey value
be_falsy be_falsey be falsy
a_falsy_value be_falsey a falsy value