Skip to content

Instantly share code, notes, and snippets.

@jtadeulopes
jtadeulopes / server.md
Last active March 29, 2024 10:23
Server setup with ubuntu, nginx and puma for rails app.

Update and upgrade the system

sudo apt-get update && sudo apt-get upgrade && sudo apt-get dist-upgrade && sudo apt-get autoremove
sudo reboot

Configure timezone

@radiosilence
radiosilence / 1-vanilla.coffee
Last active December 24, 2015 09:59
Three ways of chaining callbacks that are dependant on the previous one. In CoffeeScript.
http = require 'http'
yellIP = (callbacks, data) ->
console.log "OI!! YOUR IP IS #{data.ip}!!!"
printIP = (callbacks, data) ->
console.log "Your IP address: #{data.ip}"
parseJSON = (callbacks, string) ->
callbacks.shift()(callbacks, JSON.parse(string))
@vitorgalvao
vitorgalvao / Right Click.applescript
Last active March 16, 2023 14:30
Make right-clicking on OSX accessible via a keyboard shortcut
(*
A [native solution][1] exists but it suffers from a major flaw: it right-clicks where the cursor is, not what on the selection.
This code addresses that limitation, though it only works on Finder windows and not the Desktop.
You can install it as a [Finder Service, and later asign it a keyboard shortcut][2].
[1]: http://stackoverflow.com/questions/9171613/right-click-shortcut-for-mac-lion-os
[2]: http://www.macosxautomation.com/services/learn/tut01/index.html
*)
@daz
daz / f1calendar.rb
Last active December 14, 2015 14:59
Formula1 calendar script. P1-3, qualifying. and race start times for the year
# Dependencies
#
# $ gem install icalendar
#
# Usage
#
# $ git clone https://gist.github.com/5104840.git f1calendar
# $ ruby f1calendar/f1calendar.rb
#
# FORMULA 1 GRANDE PRÊMIO DO BRASIL 2015 - Sao Paulo - 2015-11-13 12:00:00 UTC - Practice 1
@Tafkas
Tafkas / computeSunrise.js
Last active August 3, 2023 20:04
A simple sunrise-sunset algorithm taken from http://williams.best.vwh.net/sunrise_sunset_algorithm.htm in JavaScript
function computeSunrise(day, sunrise) {
/*Sunrise/Sunset Algorithm taken from
http://williams.best.vwh.net/sunrise_sunset_algorithm.htm
inputs:
day = day of the year
sunrise = true for sunrise, false for sunset
output:
time of sunrise/sunset in hours */
@daz
daz / appleevent.rb
Created September 13, 2012 04:09
Watch for Apple event video posting
#!/usr/bin/ruby
# encoding: utf-8
# Pings Apple events page until the video is posted
# Videos are usually live ~6 hours after official start time
#
# $ git clone https://gist.github.com/3711799.git appleevent
# $ ruby appleevent/appleevent.rb
require 'date'
@matthewlehner
matthewlehner / user.rb
Created May 30, 2012 17:47 — forked from andresgutgon/user.rb
Migrate Authlogic SHA512 Passwords to BCryt
# Because we have some old legacy users in the database, we need to
# override #has_secure_passwords' method for checking if a password is valid.
# We first ask if the password is valid, and if it throws an InvalidHash
# exception, we know that we're dealing with a legacy user, so we check the
# password against the SHA1 algorithm that was used to hash the password in
# the old database.
#SOURCES OF SOLUTION:
# http://stackoverflow.com/questions/6113375/converting-existing-password-hash-to-devise
# https://github.com/binarylogic/authlogic/blob/master/lib/authlogic/crypto_providers/sha512.rb
@brookr
brookr / config.ru
Created April 16, 2012 04:36
Rackup file I use for running WordPress on Pow
# config.ru for Pow + Wordpress, based on http://stuff-things.net/2011/05/16/legacy-development-with-pow/
# added hackery to work around wordpress issues - Patrick Anderson (patrick@trinity-ai.com)
# clearly this could be cleaner, but it does work
require 'rack'
require 'rack-legacy'
require 'rack-rewrite'
# patch Php from rack-legacy to substitute the original request so
# WP's redirect_canonical doesn't do an infinite redirect of /
@barkerja
barkerja / find_my_friends.js
Created February 15, 2012 03:48
Find My Friends
var options, req, request;
request = require('request');
options = {
uri: 'https://p04-fmfmobile.icloud.com/fmipservice/friends/{account_id}/{unique_device_id}/minCallback/selFriend/refreshClient',
method: 'POST',
headers: {
'X-Apple-AuthScheme': 'Forever',
'Content-type': 'application/json'
@rstacruz
rstacruz / index.md
Last active November 3, 2023 09:56
Rails models cheatsheet

Rails Models

Generating models

$ rails g model User

Associations

belongs_to

has_one