Skip to content

Instantly share code, notes, and snippets.

Avatar

Devon Estes devonestes

View GitHub Profile
View gist:f1f342152a6b6bca19f4
# When we're working with validations in AR, remember that most of them are accepting hashes as arguments.
# For example, we could re-write
validates :email, { :uniqueness => true }
# as
validates(:email, { :uniqueness => true })
# which pretty clearly shows that we have two arguments for the validates method, a symbol and a hash
View gist:6a7c0059106946bf743c
$(document).ready(function() {
navigator.geolocation.getCurrentPosition(successCallback,errorCallback,options);
});
var weekdays = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
var dayOfWeekIndex = (new Date()).getDay();
View gist:e49eb33d95aa746db412
View count_bug_script.rb
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
gem 'rails', '~> 4.2.3'
View struct_change.ex
iex(1)> defmodule Tester do
...(1)> defstruct [:first, :second]
...(1)> def foo_to_bar(struct = %{__struct__: struct_module}) do
...(1)> updated_list = struct
...(1)> |> Map.from_struct
...(1)> |> Enum.map(fn({key, value}) ->
...(1)> if value == :foo do
...(1)> {key, :bar}
...(1)> else
...(1)> {key, value}
@devonestes
devonestes / twitter_pruner.rb
Created Mar 20, 2018
Delete your old tweets
View twitter_pruner.rb
require 'twitter'
client = Twitter::REST::Client.new do |config|
config.consumer_key = ""
config.consumer_secret = ""
config.access_token = ""
config.access_token_secret = ""
end
def collect_with_max_id(collection=[], max_id=nil, &block)
View desktop_header.jsx
import Header from './header.jsx';
function headerFun(input) {
<h1>{input.name}</h1>
}
function DesktopHeader(input) {
<Header {...{input, headerFun}} />
}
View send_after.ex
defmodule SendAfter do
def send_after(pid, message, nanoseconds) do
{_, os_name} = :os.type()
increment =
if os_name == :Windows do
# monotonic time for Windows in miliseconds, in Linux and MacOS it's nanoseconds
# so we'll need to convert to miliseconds for windows
nanoseconds / 1_000_000
else
nanoseconds
@devonestes
devonestes / trace_issue.escript
Created Aug 1, 2018
Reproduction escript for trace/3 wierdness
View trace_issue.escript
#!/usr/bin/env escript
%% -*- erlang -*-
%%! -smp enable -sname wtf
main(_) ->
process_flag(trap_exit, true),
ToMap = lists:seq(1, 50),
MapFun = fun() ->
lists:map(fun(N) -> N end, ToMap)
end,
start_runner(MapFun),
@devonestes
devonestes / comprehension.exs
Created Feb 27, 2019
Filter map varieties in Elixir
View comprehension.exs
for num <- [1, 2, 3], num < 3, do: num * 2