Skip to content

Instantly share code, notes, and snippets.

@mshafrir
mshafrir / states_hash.json
Created May 9, 2012 17:05
US states in JSON form
{
"AL": "Alabama",
"AK": "Alaska",
"AS": "American Samoa",
"AZ": "Arizona",
"AR": "Arkansas",
"CA": "California",
"CO": "Colorado",
"CT": "Connecticut",
"DE": "Delaware",
@dergachev
dergachev / GIF-Screencast-OSX.md
Last active April 19, 2024 11:00
OS X Screencast to animated GIF

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application:

@joost
joost / ruby_google_analytics_server_to_server.md
Last active November 27, 2023 15:43
Google Analytics API (server-to-server) using Ruby
import Foundation
extension String
{
var length: Int {
get {
return countElements(self)
}
}
@wrburgess
wrburgess / gist:5528649
Last active November 24, 2022 15:29
Backup Heroku Postgres database and restore to local database

Grab new backup of database

Command: heroku pgbackups:capture --remote production

Response: >>> HEROKU_POSTGRESQL_COLOR_URL (DATABASE_URL) ----backup---> a712

Get url of backup download

Command: heroku pgbackups:url [db_key] --remote production

@jwo
jwo / registrations_controller.rb
Created September 30, 2011 23:11
API JSON authentication with Devise
class Api::RegistrationsController < Api::BaseController
respond_to :json
def create
user = User.new(params[:user])
if user.save
render :json=> user.as_json(:auth_token=>user.authentication_token, :email=>user.email), :status=>201
return
else
@brentsimmons
brentsimmons / gist:5810992
Last active January 3, 2021 02:22
Detect a tap on a URL inside a UITextView. Note: the rs_links method isn't included -- you'll need something that takes text and returns an array of detected links. This gist just demonstrates walking through the UITextView characters.
@implementation UITextView (RSExtras)
static BOOL stringCharacterIsAllowedAsPartOfLink(NSString *s) {
/*[s length] is assumed to be 0 or 1. s may be nil.
Totally not a strict check.*/
if (s == nil || [s length] < 1)
return NO;
@PrinceNebulon
PrinceNebulon / NoChromeButton.xaml
Created January 27, 2012 22:04
WPF "No Chrome Button" style
<!-- Style -->
<Style x:Key="NoChromeButton" TargetType="{x:Type Button}">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Padding" Value="1"/>
<Setter Property="Template">
<Setter.Value>
@poteto
poteto / flatten_nested_json.ex
Last active April 20, 2018 16:52
Flatten deeply nested Map in Elixir
defmodule Json do
def flatten(%{} = json) do
json
|> Map.to_list()
|> to_flat_map(%{})
end
def flatten(%{} = json) when json == %{}, do: %{}
defp to_flat_map([{_k, %{} = v} | t], acc), do: to_flat_map(Map.to_list(v), to_flat_map(t, acc))
defp to_flat_map([{k, v} | t], acc), do: to_flat_map(t, Map.put_new(acc, k, v))
@clweathers
clweathers / UIView+DEFrameAdditions.h
Last active December 10, 2015 23:08
FRAMED: A UIView Category
//
// UIView+DEFrameAdditions.h
//
// Copyright (c) 2011-2013 Double Encore, Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
// Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
// Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the distribution. Neither the name of the Double Encore Inc. nor the names of its
// contributors may be used to endorse or promote products derived from this software without specific prior written permission.