Skip to content

Instantly share code, notes, and snippets.

@rauchg
rauchg / README.md
Last active January 6, 2024 07:19
require-from-twitter
echo "* Updating system"
sudo apt-get update
sudo apt-get -y upgrade
echo "* Installing packages"
sudo apt-get -y install build-essential libxml2-dev libxslt1-dev git-core nginx redis-server postgresql-client libpq5 libpq-dev curl nodejs htop
sudo locale-gen pt_PT.UTF-8
sudo dpkg-reconfigure locales
echo "* Installing rvm"
@ghinda
ghinda / object-to-form-data.js
Last active March 30, 2024 18:51
JavaScript Object to FormData, with support for nested objects, arrays and File objects. Includes Angular.js usage.
// takes a {} object and returns a FormData object
var objectToFormData = function(obj, form, namespace) {
var fd = form || new FormData();
var formKey;
for(var property in obj) {
if(obj.hasOwnProperty(property)) {
if(namespace) {
@guilhermesimoes
guilhermesimoes / line_count_benchmark.rb
Last active September 11, 2023 09:36
Ruby Benchmark: Counting the number of lines of a file
# gem install benchmark-ips
require "benchmark/ips"
path = "lib/rubycritic/cli/options.rb"
Benchmark.ips do |x|
x.report("read + each_line") { File.read(path).each_line.count }
x.report("open + each_line") { File.open(path, "r").each_line.count }
@brianstorti
brianstorti / priority_queue.rb
Last active November 17, 2022 16:14
Priority queue implementation in Ruby
class PriorityQueue
attr_reader :elements
def initialize
@elements = [nil]
end
def <<(element)
@elements << element
bubble_up(@elements.size - 1)
@nunosilva800
nunosilva800 / dup_ids.js
Created November 6, 2014 18:52
Jquery snippet to find duplicated IDs in DOM.
$('[id]').each(function(){
var ids = $('[id="'+this.id+'"]');
if(ids.length>1 && ids[0]==this)
console.warn('ID #'+this.id+' found '+ids.length+' times');
});
@mattetti
mattetti / multipart_upload.go
Last active March 6, 2024 08:07
Example of doing a multipart upload in Go (golang)
package main
import (
"bytes"
"fmt"
"io"
"log"
"mime/multipart"
"net/http"
"os"
ActiveAdmin::Dashboards.build do
# Add this section in your dashboard...
section "Background Jobs" do
now = Time.now.getgm
ul do
li do
jobs = Delayed::Job.where('failed_at is not null').count(:id)
link_to "#{jobs} failing jobs", admin_jobs_path(q: {failed_at_is_not_null: true}), style: 'color: red'
end
module WillPaginate
module ActionView
def will_paginate(collection = nil, options = {})
options[:renderer] ||= FoundationLinkRenderer
super.try :html_safe
end
class FoundationLinkRenderer < LinkRenderer
protected
@Mithrandir0x
Mithrandir0x / gist:3639232
Created September 5, 2012 16:15
Difference between Service, Factory and Provider in AngularJS
// Source: https://groups.google.com/forum/#!topic/angular/hVrkvaHGOfc
// jsFiddle: http://jsfiddle.net/pkozlowski_opensource/PxdSP/14/
// author: Pawel Kozlowski
var myApp = angular.module('myApp', []);
//service style, probably the simplest one
myApp.service('helloWorldFromService', function() {
this.sayHello = function() {
return "Hello, World!"