Skip to content

Instantly share code, notes, and snippets.

View sowenjub's full-sized avatar
🏝️
Living in Paraside

Arnaud Joubay sowenjub

🏝️
Living in Paraside
View GitHub Profile
@septerr
septerr / Rails Base64 encoded HMAC-SHA1
Last active June 17, 2016 06:31
Base64 encoded HMAC-SHA1 in iOS and Rails
secret = "xxx"
data = "http://someurl?someparams"
hmac = OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha1'), secret.encode("ASCII"), data.encode("ASCII"))
signature = Base64.encode64(hmac).chomp
@jsteiner
jsteiner / database_cleaner.rb
Created January 10, 2014 20:31
Database Cleaner
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
config.before(:each, js: true) do
@gabrielemariotti
gabrielemariotti / build.gradle
Last active November 22, 2024 19:55
Use signing.properties file which controls which keystore to use to sign the APK with gradle.
android {
signingConfigs {
release
}
buildTypes {
release {
signingConfig signingConfigs.release
}
@gevans
gevans / encryption-decryption.rb
Created July 16, 2013 00:24
A couple examples of using asymmetric RSA signing and encryption using Ruby's OpenSSL libraries.
require 'openssl'
key = OpenSSL::PKey::RSA.new(2048)
p encrypted_string = key.public_encrypt('my plaintext string', OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING)
p decrypted_string = key.private_decrypt(encrypted_string, OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING)
@bantic
bantic / rails_route_recognizer.rb
Last active September 9, 2022 12:22
Programmatically list all routes (/paths) from within a rails app.
class RouteRecognizer
attr_reader :paths
# To use this inside your app, call:
# `RouteRecognizer.new.initial_path_segments`
# This returns an array, e.g.: ['assets','blog','team','faq','users']
INITIAL_SEGMENT_REGEX = %r{^\/([^\/\(:]+)}
def initialize
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Information</key>
<dict>
<key>Description</key>
<string>Map Rails ActiveSupport timezones to iOS readable timezone IDs.</string>
<key>Version</key>
<string>1.0</string>
@ralgh
ralgh / dabblet.css
Last active March 27, 2016 16:23
CSS image crop. Forces image to 4:3 aspect ratio cropping at the middle. http://dabblet.com/gist/4711695
/**
* CSS image crop. Forces image to 4:3 aspect ratio cropping at the middle.
* http://dabblet.com/gist/4711695
*/
.img-crop,
.img-crop img{
width: 100%; /* gotta be responsive these days */
}
.img-crop{
background-color: #ededed; /* some background color for short images */
@joost
joost / google_timezone.rb
Created January 30, 2013 19:50
Get time zone id of a location by latitude and longitude (lat, lng).
# See: https://developers.google.com/maps/documentation/timezone/
# Uses HTTParty gem (https://github.com/jnunemaker/httparty).
# Usage:
# GoogleTimezone.search(:lat => 51.38494009999999, :lng => -0.3514683)['timeZoneId']
class GoogleTimezone
include HTTParty
base_uri 'https://maps.googleapis.com'
@justinHowlett
justinHowlett / gist:4611988
Last active July 9, 2024 11:53
Determine if a UIImage is generally dark or generally light
BOOL isDarkImage(UIImage* inputImage){
BOOL isDark = FALSE;
CFDataRef imageData = CGDataProviderCopyData(CGImageGetDataProvider(inputImage.CGImage));
const UInt8 *pixels = CFDataGetBytePtr(imageData);
int darkPixels = 0;
int length = CFDataGetLength(imageData);
@benvium
benvium / example.h
Created November 29, 2012 13:21
Adding and catching links in a UILabel on iOS5 when you're designing with Interface Builder / Storyboards.
#import "TTTAttributedLabel.h"
@interface CVSignupViewController : UITableViewController <TTTAttributedLabelDelegate> {
IBOutlet TTTAttributedLabel* _legalLabel;
}
@end