Skip to content

Instantly share code, notes, and snippets.

View AntouanK's full-sized avatar

Antonios Karamitros AntouanK

View GitHub Profile

Airbnb JavaScript Style Guide() {

A mostly reasonable approach to JavaScript

Table of Contents

  1. Types
  2. Objects
  3. Arrays

Transparent Git Encryption

This document has been modified from its [original format][m1], which was written by Ning Shang ([email protected]). It has been updated and reformatted into a [Markdown][m2] document by [Woody Gilk][m3] and [republished][m4].

Description

When working with a remote git repository which is hosted on a third-party storage server, data confidentiality sometimes becomes

// find out if a DOM element is within the viewport top/bottom
var ele = // some DOM element
function(){
var bodyHeight = document.body.getBoundingClientRect().height;
var rect = ele.getBoundingClientRect();
if(rect.bottom > 0 && rect.top < bodyHeight){
console.log('in');
} else {
console.log('out');
@AntouanK
AntouanK / LICENSE.txt
Last active August 29, 2015 14:06 — forked from addyosmani/README.md
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2014
Copyright (C) 2014 Addy Osmani @addyosmani
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<p>hi</p>
<svg xmlns="http://www.w3.org/2000/svg" height="98" width="581" viewBox="0 0 581 98"><path d="M62.9 14.9c-25-7.74-56.6 4.8-60.4 24.3-3.73 19.6 21.6 35 39.6 37.6 42.8 6.2 72.9-53.4 116-58.9 65-18.2 191 101 215 28.8 5-16.7-7-49.1-34-44-34 11.5-31 46.5-14 69.3 9.38 12.6 24.2 20.6 39.8 22.9 91.4 9.05 102-98.9 176-86.7 18.8 3.81 33 17.3 36.7 34.6 2.01 10.2.124 21.1-5.18 30.1" stroke="#000" stroke-width="4.3" fill="none" stroke-dasharray="298.87 298.87" stroke-dashoffset="980.95"></path></svg>
<script id="jsbin-javascript">

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application:

How it works

When you get the website on your browser, initially there is nothing to see. hack.ernews.info uses the HN Firebase API, so once the site is loaded, it has to make a websocket connection to Firebase ( can be really slow on some countries/connections ) and once it does, it loads the ids of the top stories, and then, it has to get info on each one of them, and then react can render the stories.

What hack.ernews.info does, is that apart from the main webserver, there is a pre-renderer server, that runs the "website" on the server, meaning that at any given point in time, it has the latest "top stories". Every 1 second, that pre-renderer sends the "#main-app" HTML content to the main server, which keeps it, injects it in a placeholder in the index.html, and React on the client knows that it won't touch it, until it loads stories.

So the user gets the index.html with the markup from the pre-renderer, and once firebase websocket has delivered all the data, react does it's magic and it's as

@AntouanK
AntouanK / emailRegExp.js
Created February 22, 2015 19:06
email RegExp
var emailRegExp = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;

Here's all you have to do to add clustering to your node.js application.

  • save this code as cluster.js, and run cluster.js instead of server.js (or /bin/www, or whatever it's called for your project)
  • the only line you'll need to change is the last line - it needs to point to the location of your server.js file
var cluster = require('cluster');

if (cluster.isMaster) {
  // Count the machine's CPUs
 var cpuCount = require('os').cpus().length;
bash-3.2$ node -v && sh ./run.sh
v0.10.36
Version 1
Called v1, util.yo("man") 1.000.000 times in 0.005742424 sec
Called v1, util.yo("man") 10.000.000 times in 0.046646901 sec
Called v1, util.yo("man") 100.000.000 times in 0.461483307 sec
Called v1, util.yo("man") 1.000.000.000 times in 4.760366051 sec
Version 2
Called v2, util.yo("man") 1.000.000 times in 0.005232417 sec