Skip to content

Instantly share code, notes, and snippets.

View devhero's full-sized avatar
😁

Andrea Parisi devhero

😁
  • devhero
  • Milan
View GitHub Profile
@tokland
tokland / ar_arel_wrapper.rb
Last active March 5, 2024 06:22
Simple wrapper over arel
require 'active_record'
require 'arel'
# Ruby-like syntax in AR conditions using the underlying Arel layer (Rails >= 3.0).
#
# What you would usually write like this:
#
# User.where(["users.created_at > ? AND users.name LIKE ?", Date.yesterday, "Mary"])
#
# can now be written like this (note those parentheses required by the operators precedences):
@lost-theory
lost-theory / gist:3005268
Created June 27, 2012 16:35
consume JSON REST API blueprint inside flask app
from flask import Flask, jsonify, Blueprint, current_app
import json
## REST api ###################################################################
api = Blueprint('api', __name__)
@api.route("/users")
def users():
return jsonify(users=[
@mildmojo
mildmojo / left_join_arel_example.rb
Last active April 5, 2024 16:00
LEFT JOIN in ARel for ActiveRecord in Ruby on Rails
# Here's a contrived example of a LEFT JOIN using ARel. This is an example of
# the mechanics, not a real-world use case.
# NOTE: In the gist comments, @ozydingo linked their general-purpose ActiveRecord
# extension that works for any named association. That's what I really wanted!
# Go use that! Go: https://gist.github.com/ozydingo/70de96ad57ab69003446
# == DEFINITIONS
# - A Taxi is a car for hire. A taxi has_many :passengers.
# - A Passenger records one person riding in one taxi one time. It belongs_to :taxi.
@willurd
willurd / web-servers.md
Last active April 28, 2024 21:38
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
@mikaelbr
mikaelbr / destructuring.js
Last active April 25, 2024 13:21
Complete collection of JavaScript destructuring. Runnable demos and slides about the same topic: http://git.mikaelb.net/presentations/bartjs/destructuring
// === Arrays
var [a, b] = [1, 2];
console.log(a, b);
//=> 1 2
// Use from functions, only select from pattern
var foo = () => [1, 2, 3];
@toolmantim
toolmantim / sidetiq_schedule_time_zone_additions.rb
Last active November 30, 2016 18:59
An addition to Sidetiq to make it easier to declare the worker's schedule's timezone. Assumes ActiveRecord::TimeZone is available.
# Timezone extension to Sidetiq
Sidetiq::Schedulable::ClassMethods.class_eval do
# Sets the time zone for the recurrence rules.
#
# Example:
#
# class MyWorker
# include Sidekiq::Worker
# include Sidetiq::Schedulable
#
@tibbiyelininja
tibbiyelininja / absurl.py
Last active January 12, 2017 09:48
Django Absolute URL Node with Active Property
from django.template import Library
from django.template.defaulttags import URLNode, url
register = Library()
class AbsoluteURL(str):
pass
class AbsoluteURLNode(URLNode):
def render(self, context):
@Couto
Couto / webpack.js
Last active November 11, 2020 17:53
Fetch polyfill with webpack
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var path = require('path');
var folders = {
APP: path.resolve(__dirname, '../app'),
BUILD: path.resolve(__dirname, '../build'),
BOWER: path.resolve(__dirname, '../bower_components'),
NPM: path.resolve(__dirname, '../node_modules')
};
@twoneks
twoneks / remote heroku
Created April 20, 2015 15:43
add remote heroku
# remote list
git remote -v
# add heroku app remote
heroku git:remote --app brenda-kp
git remote -v
# heroku https://git.heroku.com/brenda-kp.git
# rename local remote
@maximum-pixels
maximum-pixels / paginate_helper.rb
Created November 26, 2015 15:05
This is a custom link renderer that will format the pagination bar with Bootstrap4 as well as AJAX (i.e. data-remote="true") to use jquery-ujs rails
module PaginateHelper
class PaginateJSLinkRenderer < WillPaginate::ActionView::LinkRenderer
def prepare(collection, options, template)
options[:params] ||= {}
options[:params]['_'] = nil
super(collection, options, template)
end
protected
def html_container(html)