Skip to content

Instantly share code, notes, and snippets.

View nabilfreeman's full-sized avatar
🤗
hello wrold

Freeman nabilfreeman

🤗
hello wrold
View GitHub Profile
@nabilfreeman
nabilfreeman / gist:bd0d413993ddfc964c18
Created October 7, 2014 22:48
instanceof Element returns false
I had a problem with a site my widget was embedded on.
var el = document.createElement("div");
el instanceof Element;
>>> false
wat...
every other site on the planet returned true.
It turns out the culprit was Mootools v1.11.
@nabilfreeman
nabilfreeman / gist:7e82aa5ac4ef172d22c5
Created May 20, 2015 22:52
SOLVED: discoveryd eating up battery and CPU on Mac OS X Yosemite 10.10.3
discoveryd is completely fucked in some way in Yosemite. It randomly starts using up 100% CPU and doesn't stop until you reboot or the laptop dies.
To fix the CPU/battery rape, you need to restart the service with these shell commands:
launchctl unload -w /System/Library/LaunchDaemons/com.apple.discoveryd.plist
launchctl load -w /System/Library/LaunchDaemons/com.apple.discoveryd.plist
No sudo required. The problem will randomly return after restarting the service, so I configured launchd to run a shell script with those commands in it every hour.
No more problems, and it appears to have caused no side effects.
// AWS settings
public static function AWS_ACCESS_KEY_ID(){
if(isset($_SERVER['AWS_ACCESS_KEY_ID'])){
return $_SERVER['AWS_ACCESS_KEY_ID'];
} else {
return "XXX";
}
}
public static function AWS_SECRET_KEY(){
if(isset($_SERVER['AWS_SECRET_KEY'])){
@nabilfreeman
nabilfreeman / lambda-deploy.sh
Created August 22, 2016 09:24
AWS Lambda deploy script for Node.js
# AWS Lambda Node.js deploy script
# @author Nabil Freeman <nabil@instafork.com> (https://github.com/nabilfreeman)
# ***************************************
# Environment variables required:
# AWS_ACCESS_KEY_ID=XXXXXXX
# AWS_SECRET_ACCESS_KEY=XXXXXXXX
# AWS_DEFAULT_REGION=eu-west-1
# LAMBDA_FUNCTION_NAME=asdfghjkl
@nabilfreeman
nabilfreeman / restart-codeship-lambda.js
Last active November 9, 2017 19:44
Restart Codeship build from AWS Lambda
const https = require('https');
const { CODESHIP_KEY, PROJECT_ID } = process.env;
const getBuilds = () => {
console.time('Fetching builds...');
return new Promise((resolve, reject) => {
const host = 'codeship.com';
const path = `/api/v1/projects/${PROJECT_ID}.json?api_key=${CODESHIP_KEY}`;
const options = {
@nabilfreeman
nabilfreeman / lambda-redirect-to-trailing-slash.js
Last active March 7, 2023 20:31
Redirect to trailing slashes on CloudFront with AWS Lambda. (all this because S3 uses 302 redirects instead of 301)
'use strict';
const path = require('path')
const redirect = new_url => {
return {
status: '301',
statusDescription: 'Moved Permanently',
headers: {
location: [{
@nabilfreeman
nabilfreeman / shadowsocks-relay-haproxy.cfg
Last active April 3, 2023 00:00
HAProxy Shadowsocks relay example. You can run this on a server in China with good peering, and then proxy traffic to your outside server. Speed will be better (and improved obfuscation).
# 1. Install haproxy on Ubuntu.
# 2. Edit file path: /etc/haproxy/haproxy.cfg
# 3. Run with: haproxy -f /etc/haproxy/haproxy.cfg
# 4. haproxy will run in the background, so you can disconnect safely.
# 5. Point your Shadowsocks client at <CHINA IP>:8001 (or 8002, etc.) - you will actually be connected to your interational server!
global
defaults
log global
@nabilfreeman
nabilfreeman / copyToFat32.sh
Created November 8, 2018 12:18
FAT32 File copier & splitter (works with Multiman)
#!/bin/bash
# Are you using Mac OS X?
# You probably need to install a newer version of split for this to work.
# try `brew install coreutils`
# or `sudo port install coreutils`
# set a part size that works with FAT32 drives
PART_SIZE=3999
# nice little intro
@nabilfreeman
nabilfreeman / copyToFat32.sh
Created November 8, 2018 12:18
FAT32 File copier & splitter (works with Multiman)
#!/bin/bash
# Are you using Mac OS X?
# You probably need to install a newer version of split for this to work.
# try `brew install coreutils`
# or `sudo port install coreutils`
# set a part size that works with FAT32 drives
PART_SIZE=3999
# nice little intro
@nabilfreeman
nabilfreeman / copyToFat32.sh
Last active May 9, 2023 00:38
FAT32 File copier & splitter (works with Multiman)
#!/bin/bash
# Are you using Mac OS X?
# You need to install coreutils for this to work.
# try `brew install coreutils`
# or `sudo port install coreutils`
# set a part size that works with FAT32 drives
PART_SIZE=3999
# nice little intro