Skip to content

Instantly share code, notes, and snippets.

View tlatsas's full-sized avatar

Tasos Latsas tlatsas

View GitHub Profile
@nateberkopec
nateberkopec / 0.result.md
Last active January 18, 2024 11:20 — forked from tomfuertes/0.result.md
De-'Async Inject'ing Universal Analytics

De-'Async Inject' Universal Analytics

This gist applies the theory from Ilya Grigorik's Script-injected "async scripts" considered harmful on the default Universal Analytics snippet. TLDR place this above the CSS in the <head> of your document

<!-- Google Analytics Part 1: Creates window.ga, sets account, and queues pageview-->
<script>
  !function(n,t){n.GoogleAnalyticsObject=t,n[t]=n[t]||function(){(n[t].q=n[t].q||[]).push(arguments)},n[t].l=1*new Date}(window,"ga");
  ga('create', 'UA-XXXX-Y', 'auto'); // REPLACE UA-XXXX-Y w/ YOUR ACCOUNT
 ga('send', 'pageview');
@paulirish
paulirish / what-forces-layout.md
Last active June 12, 2024 11:55
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
@joekur
joekur / html_safe.md
Last active December 11, 2023 22:57
Proper Use of `html_safe`

Proper use of html_safe

Let's look at an innocuous piece of ruby. Consider some view code showing a user's name and phone number:

"#{first_name} #{last_name} #{phone}"

Great - this is very succinct, readable, and can easily be extracted to a method in a

@O-I
O-I / weighted_random_sampling.md
Last active February 21, 2024 19:02
[TIx 8] Weighted Random Sampling in Ruby

One of the many reasons I love working with Ruby is it has a rich vocabulary that allows you to accomplish your goals with a minimal amount of code. If there isn't a method that does exactly what you want, it's usually possible to build an elegant solution yourself.

Let's take the example of simulating the rolling of a die.

We can represent a die as an array of its faces.

die = [*?⚀..?⚅]
# => ["⚀", "⚁", "⚂", "⚃", "⚄", "⚅"]
@tlatsas
tlatsas / honeypot.py
Last active August 29, 2015 14:10
returns and logs the request headers
import sys
import json
import logging
from flask import Flask
from flask import request
from flask import Response
# log handler
stdout_logh = logging.getLogger()
@bjaglin
bjaglin / remove-orphan-images.sh
Last active March 31, 2024 22:54
Remove orphan layers left by the "file" storage backend of the docker registry, heavily inspired by https://gist.github.com/shepmaster/53939af82a51e3aa0cd6
#!/bin/bash
set -eu
shopt -s nullglob
readonly base_dir=/var/lib/docker/registry
readonly output_dir=$(mktemp -d -t trace-images-XXXX)
readonly jq=/usr/bin/jq
readonly repository_dir=$base_dir/repositories
@mad9scientist
mad9scientist / Instructions
Created May 22, 2014 14:58
Hide/Remove Pocket context menu item from Firefox's Context menu
# Hide/Remove Pocket Content Menu from Firefox
Using the above custom user chrome style you can hide [Pocket's](http://getpocket.com) context menu item from Firefox context (right click) menu. I did this because the menu option is in the same place that copy is usually located at, and thus messes with my workflow/muscle memory.
This does not use any special plugins/addons to work, just a function of Firefox (tested on version 29) and [Pocket Service](https://getpocket.com/firefox/?a=firefox) 1.0.
## Known issue
* If the menu label changes this file will need to be updated.
* This item does not use a ID, and may hide other items (I don't know of this happening, but still is possible)
require 'nokogiri'
require 'open-uri'
# Get a Nokogiri::HTML:Document for the page we're interested in...
doc = Nokogiri::HTML(open('http://www.google.com/search?q=tenderlove'))
# Do funky things with it using Nokogiri::XML::Node methods...
####
#!/usr/bin/env python
# Quick and dirty demonstration of CVE-2014-0160 by
# Jared Stafford (jspenguin@jspenguin.org)
# Modified so that it finds cookies
import sys
import struct
import socket
import time
import select
@travismillerweb
travismillerweb / matchmedia.js
Created March 30, 2014 17:03
JS - Match Media Function
/*
JS - Media Match Function
Use JavaScript's matchMedia Method to detect the type of device you are using, and invoke/activate functions based on those criteria.
Reference Links:
http://davidwalsh.name/orientation-change
http://davidwalsh.name/device-state-detection-css-media-queries-javascript
http://www.slideshare.net/DavidKnight5/howto-match-media-25008199