Skip to content

Instantly share code, notes, and snippets.

View eramax's full-sized avatar
🎯
Focusing

Ahmed Morsi eramax

🎯
Focusing
View GitHub Profile
@gf3
gf3 / jsonp.js
Created June 18, 2009 18:18
Simple JSONP in vanilla JS
/**
* loadJSONP( url, hollaback [, context] ) -> Null
* - url (String): URL to data resource.
* - hollaback (Function): Function to call when data is successfully loaded,
* it receives one argument: the data.
* - context (Object): Context to invoke the hollaback function in.
*
* Load external data through a JSONP interface.
*
* ### Examples
@codeguy
codeguy / slugify.js
Created September 24, 2013 13:19
Create slug from string in Javascript
function string_to_slug (str) {
str = str.replace(/^\s+|\s+$/g, ''); // trim
str = str.toLowerCase();
// remove accents, swap ñ for n, etc
var from = "àáäâèéëêìíïîòóöôùúüûñç·/_,:;";
var to = "aaaaeeeeiiiioooouuuunc------";
for (var i=0, l=from.length ; i<l ; i++) {
str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i));
}
@ptrelford
ptrelford / SmallSmallBasicParser.fsx
Created January 4, 2014 19:05
Small Small Basic Parser FParsec sample
// Type abbreviations
type label = string
type identifier = string
type index = int
type HashTable<'k,'v> = System.Collections.Generic.Dictionary<'k,'v>
/// Small Basic arithmetic operation
type arithmetic = Add | Subtract | Multiply | Divide
/// Small Basic comparison operaton
type comparison = Eq | Ne | Lt | Gt | Le | Ge
/// Small Basic logical operation
@denji
denji / http-benchmark.md
Last active October 13, 2024 00:43
HTTP(S) Benchmark Tools / Toolkit for testing/debugging HTTP(S) and restAPI (RESTful)
@etoews
etoews / secure-server.sh
Created February 18, 2014 19:01
Secure an Ubuntu server
#!/bin/bash
# This script assumes you've created this server with a key pair. If you haven't, you're not getting back in.
# Switch to everett user
adduser --shell /bin/bash --gecos "User for managing feeds" --disabled-password --home /home/everett everett
adduser everett sudo
grep -q "^#includedir.*/etc/sudoers.d" /etc/sudoers || echo "#includedir /etc/sudoers.d" >> /etc/sudoers
( umask 226 && echo "everett ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/50_everett_sh )
mkdir /home/everett/.ssh
@woollsta
woollsta / chunkify.js
Last active December 25, 2023 10:45
Fixes an issue with Google Chrome Speech Synthesis where long texts pause mid-speaking. The function takes in a speechUtterance object and intelligently chunks it into smaller blocks of text that are stringed together one after the other. Basically, you can play any length of text. See http://stackoverflow.com/questions/21947730/chrome-speech-sy…
/**
* Chunkify
* Google Chrome Speech Synthesis Chunking Pattern
* Fixes inconsistencies with speaking long texts in speechUtterance objects
* Licensed under the MIT License
*
* Peter Woolley and Brett Zamir
*/
var speechUtteranceChunker = function (utt, settings, callback) {
@dweinstein
dweinstein / android_direct.sh
Created November 19, 2014 18:42
iptable adb android
#!/bin/sh
set -x
PROXY_HOST=$(ifconfig en0 | grep "inet " | awk '{print $2}')
PROXY_PORT=8080
function adb_shell {
local cmd="$1"
adb shell "${cmd}"
}
@yurydelendik
yurydelendik / gist:f2b846dae7cb29c86d23
Last active October 1, 2024 08:02
PDF.js get/show hightlight
function getHightlightCoords() {
var pageIndex = PDFViewerApplication.pdfViewer.currentPageNumber - 1;
var page = PDFViewerApplication.pdfViewer.getPageView(pageIndex);
var pageRect = page.canvas.getClientRects()[0];
var selectionRects = window.getSelection().getRangeAt(0).getClientRects();
var viewport = page.viewport;
var selected = selectionRects.map(function (r) {
return viewport.convertToPdfPoint(r.left - pageRect.x, r.top - pageRect.y).concat(
viewport.convertToPdfPoint(r.right - pageRect.x, r.bottom - pageRect.y));
});
@carols10cents
carols10cents / c#-to-rust.md
Last active November 5, 2024 09:30
C# to Rust Cheat Sheet

Thanks to @seejee for making this for me!!!

C# to Rust Cheat Sheet

The goal of this is to have an easily-scannable reference for the most common syntax idioms in C# and Rust so that programmers most comfortable with C# can quickly get through the syntax differences and feel like they could read and write basic Rust programs.

What do you think? Does this meet its goal? If not, why not?

Variables

@etoews
etoews / secure-ubuntu-server.sh
Created February 2, 2015 18:25
Disclaimer: This is not the most secure configuration possible. This script is only intended to be more secure than the default configuration. No promises are made about this script preventing your server from getting hacked or your bike getting stolen. The bad guys are still out to get you. And running this script does not excuse you from writi…
#!/bin/bash
set -o errexit
# This script assumes you're running it initially as root and you've created it with a key pair. If you
# haven't, you'll be locked out of your server.
if [ -z "$1" ]; then
echo "Usage: $0 NON_ROOT_USER"
echo "Example: $0 foo"