Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Laurent Schaffner Loschcode

🏠
Working from home
View GitHub Profile
View each_vs_reduce.rb
# report for each
# 0.010811 0.001804 0.012615 ( 0.013084)
# report for reduce
# 0.007351 0.001876 0.009227 ( 0.009232)
n=1000000
Benchmark.bm do |x|
x.report do
puts "report for each"
View tally_vs_each.rb
# report for each
# 0.007854 0.001874 0.009728 ( 0.010521)
# report for tally
# 0.782440 0.076243 0.858683 ( 0.858839)
n=100
Benchmark.bm do |x|
x.report do
puts "report for each"
View weirdness.html
# what it looks like after a while
<svg width="160px" height="39px" viewBox="0 0 160 39" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" font-family="Rancho-Regular, Rancho" font-size="50" font-weight="normal">
<g id="email_blue" transform="translate(-374.000000, -120.000000)" fill="#FFFFFF">
<text id="AskAlfred">
<tspan x="374.897461" y="154">AskAlfred</tspan>
</text>
</g>
</g>
</svg>
View convert_enum_from_integer_to_string.rb
# MIGRATION
change_column :my_table, :status, :string
# LOGICS
module SafeEnumHelper
def self.ensure(resource:, column:, mapping:)
raw_status = resource.attributes_before_type_cast[column]
is_integer = /\A[-+]?\d+\z/ === raw_status
if is_integer
View currentIdentity(working).js
import gql from 'graphql-tag'
import EventsService from '@/services/EventsService'
import _ from 'lodash'
const CurrentIdentity = gql`
query CurrentIdentity {
currentIdentity {
id
role
token
View currentIdentity(not-working).js
import gql from 'graphql-tag'
import EventsService from '@/services/EventsService'
import _ from 'lodash'
const CurrentIdentity = gql`
query CurrentIdentity {
currentIdentity {
id
role
token
View currentIdentity(not-working).js
import gql from 'graphql-tag'
import EventsService from '@/services/EventsService'
import _ from 'lodash'
const CurrentIdentity = gql`
query CurrentIdentity {
currentIdentity {
id
role
token
@Loschcode
Loschcode / a-wonderful-world.js
Last active Mar 18, 2019
If anyone wonders why the JS world is a fucking mess
View a-wonderful-world.js
// those 2 abstract of the same library are supposed to do the exact same thing, but are written totally differently
// because no one cared about restricting the way you should use their public API.
// because there's no real public API, because JS.
const hasSubscriptionOperation = ({ query: { definitions } }) => {
return definitions.some(
({ kind, operation }) =>
kind === 'OperationDefinition' && operation === 'subscription'
)
}
View createGuest.js
import gql from 'graphql-tag'
const mutation = gql`
mutation CreateGuest {
createGuest {
token
}
}
`
View getTokenOperation.js
import _ from 'lodash'
import createGuest from '@/graphql/mutations/createGuest'
import EventsService from '@/services/EventsService'
export default vm => {
const events = new EventsService(vm)
const perform = async () => {
if (getToken() == null) await connectGuest()
return getToken()