Skip to content

Instantly share code, notes, and snippets.

View aziz's full-sized avatar

Allen Bargi aziz

  • Gothenburg, Sweden
View GitHub Profile
@myshov
myshov / function_invocation.js
Last active January 21, 2024 15:14
11 Ways to Invoke a Function
console.log(1);
(_ => console.log(2))();
eval('console.log(3);');
console.log.call(null, 4);
console.log.apply(null, [5]);
new Function('console.log(6)')();
Reflect.apply(console.log, null, [7])
Reflect.construct(function(){console.log(8)}, []);
Function.prototype.apply.call(console.log, null, [9]);
Function.prototype.call.call(console.log, null, 10);
@developit
developit / hydra-alias.md
Last active February 27, 2020 01:54
Alias to invoke Chrome Canary w/ tracing, for IRHydra

An Alias to run Chrome with tracing enabled

For Chrome Canary:

alias hydra='/Applications/Google\ Chrome\ Canary.app/Contents/MacOS/Google\ Chrome\ Canary --no-sandbox --js-flags="--user-data-dir=/tmp/profile --trace-hydrogen --trace-phase=Z --trace-deopt --code-comments --hydrogen-track-positions --redirect-code-traces"'

For regular ol' Chrome:

Minimum Viable Async with Node 6

With the release of Node 6.0.0, the surface of code that needs transpilation to use ES6 features has been reduced very dramatically.

This is what my current workflow looks like to set up a minimalistic and fast microservice using micro and async + await.

The promise

@tlrobinson
tlrobinson / giphy.sh
Created March 14, 2016 21:59
Command-line Giphy using iTerm2's imgcat (also requires curl and jq)
#!/bin/sh
tag="$(echo "$*" | sed 's/ /+/')"
random_api_url="http://api.giphy.com/v1/gifs/random?api_key=dc6zaTOxFJmzC&tag=$tag"
gif_url="$(curl "$random_api_url" 2> /dev/null | jq '.data.image_url' -r)"
curl "$gif_url" 2> /dev/null | imgcat
@eyecatchup
eyecatchup / apple-meta-insanity.html
Created February 8, 2015 12:28
Insanity of Apple-specific meta tags..
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Apple Meta Insanity</title>
<!--
APPLE WEB APP META TAGS
-->
@buren
buren / rails_web_console_param.rb
Last active February 13, 2016 18:16
Attach a rails web console to any page by adding ?web_console=
# config/initializers/web_console.rb
WebConsoleBeforeAction = ->(controller) do
controller.console if controller.params[:web_console]
end
ApplicationController.before_action(WebConsoleBeforeAction) if defined?(WebConsole) && Rails.env.development?
# NOTE:
# For security reasons only do this in development.
@chris-rock
chris-rock / crypto-buffer.js
Last active November 24, 2023 09:48
Encrypt and decrypt buffers in nodejs
// Part of https://github.com/chris-rock/node-crypto-examples
var crypto = require('crypto'),
algorithm = 'aes-256-ctr',
password = 'd6F3Efeq';
function encrypt(buffer){
var cipher = crypto.createCipher(algorithm,password)
var crypted = Buffer.concat([cipher.update(buffer),cipher.final()]);
return crypted;

This is all based on the [alpha release][1].

Properties

From the built-in help system:

For many settings, TextMate will look for a .tm_properties file in the current folder, and in any parent folders (up to the user’s home folder).

These are simple «setting» = «value» listings, where «value» is a format string in which other variables can be referenced.

@branneman
branneman / better-nodejs-require-paths.md
Last active April 27, 2024 04:16
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

const Article = require('../../../../app/models/article');

Those suck for maintenance and they're ugly.

Possible solutions

@kozo002
kozo002 / jquery.brightness.js
Created October 3, 2013 07:38
Get brightness from background color with jQuery
jQuery.fn.brightness = function() {
var bg_color, rgba, y;
bg_color = this.css('background-color');
if ((bg_color != null) && bg_color.length) {
rgba = bg_color.match(/^rgb(?:a)?\(([0-9]{1,3}),\s([0-9]{1,3}),\s([0-9]{1,3})(?:,\s)?([0-9]{1,3})?\)$/);
if (rgba != null) {
if (rgba[4] === '0') {
if (this.parent().length) return this.parent().brightness();
} else {
y = 2.99 * rgba[1] + 5.87 * rgba[2] + 1.14 * rgba[3];