Skip to content

Instantly share code, notes, and snippets.

View ZakharDay's full-sized avatar

ZakharDay ZakharDay

View GitHub Profile
@thejbsmith
thejbsmith / Rails Singleton Model
Last active April 16, 2024 00:29
Rails Singleton Model
Rails Singleton Model
Taken from:
http://stackoverflow.com/questions/399447/how-to-implement-a-singleton-model/12463209#12463209
@MathewReiss
MathewReiss / phone.js
Created June 4, 2015 17:09
Pokedex phone.js File
var DEBUG = true;
//var name = "name", type = "type", stage = "stage", caught = "caught";
var grass = "grass", water = "water", fire = "fire", bug = "bug",
psychic = "psychic", flying = "flying", ghost = "ghost", fighting = "fighting",
normal = "normal", poison = "poison", electric = "electric", ground = "ground",
fairy = "fairy", rock = "rock", ice = "ice", dragon = "dragon";
var Pokemon = [
{ name : "MissingNo", type : "blank", stage : 100, caught : 0, species : "Glitch Pokemon"},
@GaspardP
GaspardP / sha256.js
Created June 4, 2015 15:21
SHA-256 with Javascript and Web Crypto
// Computes the SHA-256 digest of a string with Web Crypto
// Source: https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest
function sha256(str) {
// Get the string as arraybuffer.
var buffer = new TextEncoder("utf-8").encode(str)
return crypto.subtle.digest("SHA-256", buffer).then(function(hash) {
return hex(hash)
})
}
@yymm
yymm / gulpfile.coffee
Last active August 29, 2015 14:16
Gulp, browserify, reactify, coffee-reactify, notify and watchify for coffeescript
#
# Ref:
# * https://gist.github.com/vojd/a2d277bc161a2674aeaa
# * https://gist.github.com/Sigmus/9253068
#
source = require 'vinyl-source-stream'
gulp = require 'gulp'
gutil = require 'gulp-util'
browserify = require 'browserify'
@nathanstilwell
nathanstilwell / apple-devices.less
Last active October 10, 2016 16:55
iPhone Media Queries
//
// Ok look, I know this is a bad idea but I'm doing this as an experiment. I'm going to get really granular with these,
// which makes them basically unsuable. But it gives a decent overview of the diversity of iThangs.
// So chill.
//
// References:
// http://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions
// https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Media_queries#-moz-device-pixel-ratio
// http://stephen.io/mediaqueries/
//
@sebmarkbage
sebmarkbage / Enhance.js
Last active February 10, 2025 06:23
Higher-order Components
import { Component } from "React";
export var Enhance = ComposedComponent => class extends Component {
constructor() {
this.state = { data: null };
}
componentDidMount() {
this.setState({ data: 'Hello' });
}
render() {
@sebmarkbage
sebmarkbage / react_legacyfactory.md
Last active March 15, 2020 00:32
Use a factory or JSX

React Element Factories and JSX

You probably came here because your code is calling your component as a plain function call. This is now deprecated:

var MyComponent = require('MyComponent');

function render() {
 return MyComponent({ foo: 'bar' }); // WARNING
@syguer
syguer / get_access_token_from_trello.rb
Last active April 23, 2019 00:31
Get access token and secret from trello
require 'oauth'
consumer = OAuth::Consumer.new(
"CONSUMER_KEY",
"CONSUMER_SECRET",
{
site: "https://trello.com",
request_token_url: "https://trello.com/1/OAuthGetRequestToken",
authorize_url: "https://trello.com/1/OAuthAuthorizeToken",
access_token_url: "https://trello.com/1/OAuthGetAccessToken"
@sebmarkbage
sebmarkbage / ElementFactoriesAndJSX.md
Last active May 17, 2022 11:06
New React Element Factories and JSX

New React Element Factories and JSX

In React 0.12, we're making a core change to how React.createClass(...) and JSX works.

If you're using JSX in the typical way for all (and only) React components, then this transition will be seamless. Otherwise there are some minor breaking changes described below.

The Problem

@hopsoft
hopsoft / db.rake
Last active February 5, 2025 13:23
Rails rake tasks for dump & restore of PostgreSQL databases
# lib/tasks/db.rake
namespace :db do
desc "Dumps the database to db/APP_NAME.dump"
task :dump => :environment do
cmd = nil
with_config do |app, host, db, user|
cmd = "pg_dump --host #{host} --username #{user} --verbose --clean --no-owner --no-acl --format=c #{db} > #{Rails.root}/db/#{app}.dump"
end
puts cmd