Skip to content

Instantly share code, notes, and snippets.

View christianhaller's full-sized avatar

Christian Haller christianhaller

View GitHub Profile
@headius
headius / meltdown_in_a_nutshell.md
Last active July 27, 2018 13:43
How Meltdown Works

Algorithm

  1. A secret byte you want to read is stored at inaccessible memory location priv_mem.
  2. The sender triggers an access exception by attempting to read priv_mem.
  3. Due to CPU optimization (out-of-order execution), the load of secret from priv_mem and the use of its value in (4) and (5) below may execute before the exception is triggered.
  4. Calculate an offset into a known array probe by multiplying secret by the width of a cache line (or whatever block size the CPU typically fetches, like a 4096-byte page). This guarantees each of those 256 possible offsets will cache separately.
  5. Load probe[offset], which causes the CPU to cache exactly one chunk of of our array, populating one cache line.
  6. The exception finally triggers, clearing the modified registers...but cached data is not excised.
  7. Iterate over all 256 offsets into probe to find out which one loads fast. You've determined the value of secret.
@ebidel
ebidel / feature_detect_es_modules.js
Last active September 4, 2023 13:56
Feature detect ES modules: both static import and dynamic import()
<!--
Complete feature detection for ES modules. Covers:
1. Static import: import * from './foo.js';
2. Dynamic import(): import('./foo.js').then(module => {...});
Demo: http://jsbin.com/tilisaledu/1/edit?html,output
Thanks to @_gsathya, @kevincennis, @rauschma, @malyw for the help.
-->
@chris-olszewski
chris-olszewski / webpack.config.js
Created August 2, 2016 21:24
Serverless v1 Webpack
var webpack = require('webpack');
module.exports = {
context: __dirname,
entry: './index',
output: {
path: __dirname,
filename: 'handler.js',
libraryTarget: 'commonjs2'
},
@ikait
ikait / index.js
Created July 4, 2015 11:48
AWS Lambda で WebP変換
'use strict';
// 全体の設定
var DST_BUCKET = 'xxxxxxxxxxx'; // WebP が格納されるバケット
var SRC_BUCKET = 'xxxxxxxxxxx'; // イベントソース
var ACCESS_KEY = 'XXXXXXXXXXXXXXXXXXXX'; // アクセスキーID
var SECRET_KEY = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; // シークレットキー
var REGION = 'ap-northeast-1'; // リージョン
var ACCEPTED_EXTENTIONS = ["png", "jpg", "gif"]; // 拡張子
@p3t3r67x0
p3t3r67x0 / pseudo_elements.md
Last active September 19, 2024 12:31
A CSS pseudo-element is used to style specified parts of an element. In some cases you can style native HTML controls with vendor specific pseudo-elements. Here you will find an list of cross browser specific pseudo-element selectors.

Styling native elements

Native HTML controls are a challenge to style. You can style any element in the web platform that uses Shadow DOM with a pseudo element ::pseudo-element or the /deep/ path selector.

video::webkit-media-controls-timeline {
  background-color: lime;
}

video /deep/ input[type=range] {
@spektraldevelopment
spektraldevelopment / JS: Casper Helper
Created August 29, 2014 01:16
Helper file for use with Casperjs
//MOUSE
var
mouse = require("mouse").create(casper),
colorizer = require('colorizer').create('Colorizer');
//Available color names are black, red, green, yellow, blue, magenta, cyan and white
//EVENTS
casper.on('remote.message', function(msg) {
this.echoRemote(msg);
@cowboy
cowboy / awesome.js
Created August 12, 2014 15:18
this code from amazon.com's source is... well, just... what web development is all about
document.write = (function(write){
var override = function() {
if(document.readyState !== "loading") { // document has finished loading - we want to intercept this call to document.write
if (window.ueLogError) {
try {
throw new Error("`document.write` called after page load on the gateway.");
}
catch(e) {
ueLogError(e, { logLevel : 'ERROR', attribution: 'gw-third-party-js' });
}
@hdragomir
hdragomir / sm-annotated.html
Last active July 27, 2024 15:01
The deferred font loading logic for Smashing Magazine. http://www.smashingmagazine.com/
<script type="text/javascript">
(function () {
"use strict";
// once cached, the css file is stored on the client forever unless
// the URL below is changed. Any change will invalidate the cache
var css_href = './index_files/web-fonts.css';
// a simple event handler wrapper
function on(el, ev, callback) {
if (el.addEventListener) {
el.addEventListener(ev, callback, false);
@marcelduran
marcelduran / gist:1e91b64849e4c0572de2
Created May 14, 2014 18:09
PhantomJS script to pseudo-retina screenshots
var page = require('webpage').create(),
address, output, size;
page.onConsoleMessage = function(msg, lineNum, sourceId) {
console.log('CONSOLE: ' + msg);
};
if (phantom.args.length < 2 || phantom.args.length > 6) {
console.log('Usage: rasterize.js URL filename WxH retina ua');
phantom.exit();
@chilts
chilts / alexa.js
Created October 30, 2013 09:27
Getting the Alexa top 1 million sites directly from the server, unzipping it, parsing the csv and getting each line as an array.
var request = require('request');
var unzip = require('unzip');
var csv2 = require('csv2');
request.get('http://s3.amazonaws.com/alexa-static/top-1m.csv.zip')
.pipe(unzip.Parse())
.on('entry', function (entry) {
entry.pipe(csv2()).on('data', console.log);
})
;