Skip to content

Instantly share code, notes, and snippets.

@jcsrb
jcsrb / gist:1081548
Created July 13, 2011 23:05
get avatar from google profiles, facebook, gravatar, twitter, tumblr
function get_avatar_from_service(service, userid, size) {
// this return the url that redirects to the according user image/avatar/profile picture
// implemented services: google profiles, facebook, gravatar, twitter, tumblr, default fallback
// for google use get_avatar_from_service('google', profile-name or user-id , size-in-px )
// for facebook use get_avatar_from_service('facebook', vanity url or user-id , size-in-px or size-as-word )
// for gravatar use get_avatar_from_service('gravatar', md5 hash email@adress, size-in-px )
// for twitter use get_avatar_from_service('twitter', username, size-in-px or size-as-word )
// for tumblr use get_avatar_from_service('tumblr', blog-url, size-in-px )
// everything else will go to the fallback
// google and gravatar scale the avatar to any site, others will guided to the next best version
@jcsrb
jcsrb / map-values-async.js
Created January 28, 2018 17:24
Lodash's .mapValues but for async functions
const mapValuesAsync = (obj, asyncFn) => {
const keys = Object.keys(obj);
const promises = keys.map(k => {
return asyncFn(obj[k]).then(newValue => {
return {key: k, value: newValue};
});
});
return Promise.all(promises).then(values => {
const newObj = {};
values.forEach(v => {
@jcsrb
jcsrb / article_image_uploader.rb
Created December 22, 2011 15:02
CarrierWave extension fix_exif_rotation, strip, quality, resize_to_fill_if_larger
class ArticleImageUploader < ImageUploader
process :fix_exif_rotation
process :strip
process :convert => 'jpg'
process :quality => 85 # Percentage from 0 - 100
version :gallery_thumb do
process :resize_to_fill => Settings.images.article_images.processing.gallery_thumb #44x44
end
let alreadyRun = document.querySelector('body').classList.contains("vl-bookmarklet");
let domainCheck = window.location.origin == "http://legaldiary.courts.ie"
function wrap(el, wrapper) {
el.parentNode.insertBefore(wrapper, el);
wrapper.appendChild(el);
}
function addStyle(styleString) {
const style = document.createElement('style');
@jcsrb
jcsrb / command.sh
Last active June 21, 2020 19:56
if you get "socket() failed (24: Too many open files) while connecting to upstream" on nginx on MacOS
echo 'kern.maxfiles=20480' | sudo tee -a /etc/sysctl.conf
echo -e 'limit maxfiles 8192 20480\nlimit maxproc 1000 2000' | sudo tee -a /etc/launchd.conf
echo 'ulimit -n 4096' | sudo tee -a /etc/profile
@jcsrb
jcsrb / gist:1496554
Created December 19, 2011 10:37
facebook, twitter, google plus in addthis all with vertical count
<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=YOUR-PROFILE-ID"></script>
<div class="addthis_default_style">
<a class="addthis_button_facebook_like" fb:like:layout="box_count" fb:like:width="48" fb:like:height="63"></a>
<div class="clearfix"></div>
<a class="addthis_button_tweet" tw:count="vertical"></a>
<div class="clearfix"></div>
<a class="addthis_button_google_plusone" g:plusone:size="tall"></a>
</div>
@jcsrb
jcsrb / .htaccess
Created December 1, 2011 13:03
A Generic .htaccess File
#taken from http://www.vipan.com/htdocs/htaccess.shtml
# Place a .htaccess file in each directory you want to protect.
########################################################################
# SECURITY / ACCESS CONTROL #
# If the web server's AllowOverride allows AUTHCONFIG to be overridden #
########################################################################
#
# Save both .htpasswd and .htgroup files in a directory above "documentroot" directory
# (e.g. not in or below /apache/htdocs) but could be below "serverroot" directory
@jcsrb
jcsrb / select.js
Last active October 10, 2018 20:33
How open a <select> element programmatically
//Thank to @Formstone https://github.com/Formstone/Selecter/blob/master/src/jquery.fs.selecter.js
if (window.document.createEvent) { // All
var evt = window.document.createEvent("MouseEvents");
evt.initMouseEvent("mousedown", false, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
el.dispatchEvent(evt);
} else if (el.fireEvent) { // IE
el.fireEvent("onmousedown");
}
@jcsrb
jcsrb / authorization.md
Created June 19, 2018 17:39 — forked from nikneroz/authorization.ex
Elixir + Phoenix Framework 1.3 + Guardian 1.0 + JWT(Refresh, Revoke, Recover) + Comeonin

Elixir + Phoenix Framework 1.3 + Guardian + JWT(Refresh, Revoke, Recover) + Comeonin

User model bootstrap

Let's generate User model and controller.

mix ecto.create # create DB table
mix phx.gen.json Accounts User users email:string password_hash:string # scaffold users structure
@jcsrb
jcsrb / extract.rb
Created March 7, 2018 15:24
Dig in hashes or arrays
def extract_stuff(stuff, path)
path.empty? stuff : extract_stuff(stuff[path.shift], path)
end