Skip to content

Instantly share code, notes, and snippets.

@lesleh
lesleh / stop_animations.js
Created September 11, 2017 15:53
Disable unintersected animations
/* global IntersectionObserver */
(function () {
'use strict'
var selectors = '.home-hero, .site-header__logo'
function callback (entries) {
var entry = entries[0]
$(entry.target).css('animation', entry.isIntersecting ? '' : 'none')
@lesleh
lesleh / unicode_glyph_count.rb
Last active August 18, 2017 22:18
Count the number of occurrences of each unicode character in a bunch of files
require 'json'
all_chars = {}
Dir["**/*.md"].each do |file|
character_data = IO.read(file).each_char.each_with_object(Hash.new(0)) do |word,counts|
counts[word] += 1
end
all_chars.merge!(character_data) do |_, oldval, newval|
@lesleh
lesleh / element_filter.js
Created October 19, 2016 11:03
Filter html elements based on a given string and array of selectors
import $ from "jquery";
export default class ElementFilter {
constructor(container, elementSelector, searchSelectors) {
this.container = container || $(document);
this.elementSelector = elementSelector;
this.searchSelectors = searchSelectors;
}
"use strict";
const GuessTheNumber = require('./guess_the_number');
module.exports = class GuessTheNumberSolver {
constructor() {
this.game = new GuessTheNumber();
}
"use strict";
let readline = require('readline');
class GuessTheNumber {
randomBetween(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
}
@lesleh
lesleh / link_hooks
Created July 1, 2015 09:46
Link git hooks from git repository files.
@lesleh
lesleh / prod_setup.sh
Last active January 27, 2016 10:18
Production server setup
#!/bin/bash
export GITHUB_USERNAME=lesleh
export GITHUB_PASSWORD=hunter2
export DB_ROOT_PASSWORD=password
# Delete the next two lines when you're done
>&2 echo "YOU NEED TO SET THE VARIABLES BEFORE RUNNING THE SCRIPT.."
exit 1
# nginx
description "nginx http daemon"
author "George Shammas <georgyo@gmail.com>"
start on (filesystem and net-device-up IFACE=lo)
stop on runlevel [!2345]
env DAEMON=/opt/nginx/sbin/nginx
env PID=/opt/nginx/logs/nginx.pid
@lesleh
lesleh / each_repo.sh
Last active August 29, 2015 14:22
Run command on all Git repositories in current directory.
#!/bin/bash
# Example usage: ./each_repo.sh 'git pull'
if [ $# -ne 1 ]; then
2>&1 echo "No command specified."
exit 1
fi
DIR=$(pwd) # $(dirname $(readlink -f $0))
@lesleh
lesleh / git_subprojects_status.sh
Created June 5, 2015 14:36
Recursively list git status for all sub projects
#!/bin/bash
DIR=$(dirname $(readlink -f $0))
find $DIR -maxdepth 2 -mindepth 2 -name .git -type d | while read REPO; do
REPO=${REPO//.git/}
echo $REPO
pushd $REPO >/dev/null
git status -s