Skip to content

Instantly share code, notes, and snippets.

View thecookieorg's full-sized avatar
:bowtie:

Marko Manojlovic thecookieorg

:bowtie:
View GitHub Profile
@thecookieorg
thecookieorg / singleton.rb
Created October 19, 2020 17:03 — forked from mssola/singleton.rb
Different ways to create the Singleton pattern in Ruby.
##
# This files shows some possible implementations of the Singleton pattern
# in Ruby. I'm not a huge fan of the Singleton pattern, but it's nice
# in some cases. In this file I'm going to implement a simple logger.
#
##
# The first implementation that can come to our minds is to create a class
# that holds an instance as a class variable that can be accessed through
@thecookieorg
thecookieorg / person.rb
Created July 13, 2020 16:19 — forked from davidbella/person.rb
Ruby: Dynamic meta-programming to create attr_accessor like methods on the fly
class Person
def initialize(attributes)
attributes.each do |attribute_name, attribute_value|
##### Method one #####
# Works just great, but uses something scary like eval
# self.class.class_eval {attr_accessor attribute_name}
# self.instance_variable_set("@#{attribute_name}", attribute_value)
##### Method two #####
# Manually creates methods for both getter and setter and then
background: linear-gradient(270deg, #5e6de3, #00d29c, #ee5253, #f368e0, #ff9f43);
background-size: 1000% 1000%;
-webkit-animation: zar-gama-loading-bar 30s ease infinite;
-moz-animation: zar-gama-loading-bar 30s ease infinite;
-o-animation: zar-gama-loading-bar 30s ease infinite;
animation: zar-gama-loading-bar 30s ease infinite;
@-webkit-keyframes zar-gama-loading-bar {
    0%{background-position:0% 50%}
    50%{background-position:100% 50%}
    100%{background-position:0% 50%}
@thecookieorg
thecookieorg / dimensions.js
Created December 8, 2018 13:06
React Native Dimensions
import React, { Component } from 'react';
import { Dimensions, View, Text } from 'react-native';
const screenWidth = Dimensions.get('screen').width;
const screenHeight = Dimensions.get('screen').height;
export default class Dimensions extends Component {
render() {
return (
<View>
import React, { Component } from 'react';
import { TouchableOpacity, View, Text } from 'react-native';
export default class MyAwesomeButton extends Component {
render() {
return (
<View>
<TouchableOpacity
style={{
backgroundColor: this.props.backgroundColor,
import React, { Component } from 'react';
import { View, Text } from 'react-native';
import MyAwesomeButton from './common/MyAwesomeButton';
export default class ClickSome extends Component {
render() {
return (
<View>
<MyAwesomeButton
buttonText="Click me!"
import React, { Component } from 'react';
import { View, Text } from 'react-native';
class User extends Component {
render() {
return (
<View>
<Text>Username: {this.props.name}</Text>
<Text>Phone number: {this.props.phone}</Text>
<Image source={this.props.avatar} style={{ width: 200, height: 150 }} />
import React, { Component } from 'react';
import { View } from 'react-native';
import Home from './Home';
import Login from './Login';
class App extends Component {
state = {
isLoggedIn: false
};
import React, { Component } from 'react';
import { View, Text } from 'react-native';
class Login extends Component {
render() {
const { containerStyle } = styles;
return (
<View style={containerStyle}>
<Text>Hello from Login</Text>
import React, { Component } from 'react';
import { View, Text } from 'react-native';
class Home extends Component {
render() {
const { containerStyle } = styles;
return (
<View style={containerStyle}>
<Text>Hello from Home!</Text>