Skip to content

Instantly share code, notes, and snippets.

View l0gicpath's full-sized avatar

Hady Mahmoud l0gicpath

View GitHub Profile
@alanpeabody
alanpeabody / notes.md
Last active August 29, 2015 14:10
Web apps in elixir
@amark
amark / allDone.js
Created November 16, 2014 10:26
parallel async JS micro library in 25LOC
var allDone = function(done){ // takes a callback that will be called as callback(errors, values) when all async parallel operations are finished.
var context = {task: {}, data: {}};
context.end = function(e,v){ return done(e,v), done = function(){} }; // this can always be called if you want to terminate early, like because an error.
context.add = function(fn, id){ // if the async operation you are doing replies with standard fn(err, value) then just pass in a string ID, else your own callback and ID.
context.task[id = (typeof fn == 'string')? fn : id] = false;
var next = function(err, val){
context.task[id] = true; // good, we're done with this one!
if(err){ (context.err = context.err || {})[id] = err } // record errors.
context.data[id] = val; // record the values.
for(var i in c.task){ if(c.task.hasOwnProperty(i)){ // loop over the async task checker
@apisandipas
apisandipas / Gulpfile.js
Created October 21, 2014 17:04
Simple Gulp Setup for SCSS and livereload
var gulp = require('gulp'),
$ = require('gulp-load-plugins')();
var config = {
scss_src: 'assets/scss/**/*.scss',
css_dest: 'assets/css'
};
gulp.task('css', function() {
gulp.src( config.scss_src )
@jmoiron
jmoiron / Makefile
Last active December 23, 2015 19:09
monte carlo pi estimation in different languages
all: monte-c monte-go monte-rs monte-gccgo
monte-go:
go build montepi.go && mv montepi monte-go
monte-rs:
rustc -O -o monte-rs montepi.rs
monte-c:
gcc -std=c99 -O2 -o monte-c montepi.c -lm
@kachayev
kachayev / concurrency-in-go.md
Last active May 4, 2025 05:48
Channels Are Not Enough or Why Pipelining Is Not That Easy
@dhoelzgen
dhoelzgen / base_controller.rb
Last active October 7, 2021 16:19
CORS in Rails 4 APIs
class API::V1::BaseController < ApplicationController
skip_before_filter :verify_authenticity_token
before_filter :cors_preflight_check
after_filter :cors_set_access_control_headers
def cors_set_access_control_headers
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Methods'] = 'POST, GET, PUT, DELETE, OPTIONS'
@rubysolo
rubysolo / router.ex
Last active March 7, 2016 03:43
CORS with Phoenix
defmodule App.Router do
use Phoenix.Router
resources "users", Controller.Users
options "/users", Controller.Users, :options
end
function get_mx($email)
{
// Get domain name from email
$domain = substr(strrchr($email, "@"), 1);
// get MX records for domain
getmxrr($domain, $mxhosts);
// Match records with three options
preg_match('/google|hotmail|yahoo/i', implode(' ', $mxhosts), $matches);
@scottburton11
scottburton11 / gist:10221751
Created April 9, 2014 02:50
Facebook RSVP using the JS SDK
<html>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '721489701236648',
status : true,
xfbml : true
});
@mtayseer
mtayseer / kill_portal.sh
Created March 16, 2014 09:47
One-liner which kills a Unix process given its name
# Kill a process, given part of its name
#
# How I'm doing it:-
#
# 1. Get a list of all processes
# 2. Grep for any process where "portal" is part of the
# command line used to launch it
# 3. I will get 2 processes: 1 of them is what I'm searching for &
# the other is just this grep command I'm running. I remove it by
# removing anything with "grep" in its command line