Skip to content

Instantly share code, notes, and snippets.

View zishe's full-sized avatar
🏠
Working from home

Alexander Kireev zishe

🏠
Working from home
  • Ko Pha Ngan, Thailand
View GitHub Profile
@clinuxrulz
clinuxrulz / Window.tsx
Last active May 13, 2024 19:46
SolidJS reusable draggable/resizable window example (requires bootstrap style sheet and an icon for grip drag corner "svgs/icons/resize%20grip.svg")
import { batch, Component, createEffect, createMemo, onCleanup, onMount } from 'solid-js';
import { createStore } from 'solid-js/store';
const Window: Component<{
title?: string,
width?: number,
height?: number,
initX?: number,
initY?: number,
}> = (props) => {
@Atinux
Atinux / async-foreach.js
Last active October 10, 2023 03:04
JavaScript: async/await with forEach()
const waitFor = (ms) => new Promise(r => setTimeout(r, ms))
const asyncForEach = async (array, callback) => {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array)
}
}
const start = async () => {
await asyncForEach([1, 2, 3], async (num) => {
await waitFor(50)

Realtime Notifications with ActionCable

In this episode we're going to be adding realtime notifications into your app using ActionCable. We've talked about notifications a few times in the past and we used AJAX polling for that. 95% of the time, polling is the solution that would be recommended for it.

But if you're looking for a good introduction into ActionCable then this is a decent one because we're only really using it for one way from the server side to the client side.

Getting started

So to get started we're starting with an app that has Bootstrap installed and then we created a Main controller with an index view which is where we will list our Notifications as for this example.

Before we generate our channels let's install a few things

@dhoelzgen
dhoelzgen / base_controller.rb
Last active October 7, 2021 16:19
CORS in Rails 4 APIs
class API::V1::BaseController < ApplicationController
skip_before_filter :verify_authenticity_token
before_filter :cors_preflight_check
after_filter :cors_set_access_control_headers
def cors_set_access_control_headers
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Methods'] = 'POST, GET, PUT, DELETE, OPTIONS'
app.directive('infiniteScroll', [
'$rootScope', '$window', '$timeout', function($rootScope, $window, $timeout) {
return {
link: function(scope, elem, attrs) {
var checkWhenEnabled, handler, scrollDistance, scrollEnabled;
$window = angular.element($window);
elem.css('overflow-y', 'scroll');
elem.css('overflow-x', 'hidden');
elem.css('height', 'inherit');
scrollDistance = 0;
@zishe
zishe / diff
Last active August 29, 2015 13:58
Ruby frameworks bench
jruby-1.7.12
puma -e production -t 100:100 <framework>.ru
wrk -t4 -c100 -d2s http://0.0.0.0:9292/
Ruby
Rack: 17800.91
Hobbit: 15742.50
Cuba: 14828.45
JRuby + Rack + Torqbox ~ 60k req/s
@Lawondyss
Lawondyss / AngularJS FlashMessage
Last active January 2, 2016 21:49
Uses CSS framework SemanticUI.
myApp = angular.module 'myApp', []
myApp.service 'FlashMessage', ($rootScope) ->
Flash = () ->
$rootScope.flashes = []
$rootScope.$on '$routeChangeSuccess', () ->
$rootScope.$broadcast 'FlashMessage:reset', $rootScope.flashes = []
return
@headius
headius / 1. results
Last active April 27, 2016 19:43
mandelbrot performance across JRuby 9k modes
# interpreted AST
system ~/projects/jruby $ jruby.bash -X-C mandelbrot.rb 20
warming up
running mandelbrot(500) for 20 iterations
4.862
4.822
4.822
4.846
5.057
@jakemmarsh
jakemmarsh / controllers.js
Last active May 20, 2019 10:15
AngularJS Service with Controller for access to Google API with Javascript Client (and RequireJS)
define(['angular', 'services'], function (angular) {
'use strict';
return angular.module('myApp.controllers', ['myApp.services'])
.controller('IndexCtrl', ['$scope', 'googleService', function ($scope, googleService) {
$scope.login = function () {
googleService.login().then(function (data) {
// do something with returned data
console.log(data.email);
@5HT
5HT / WebFrameworks.md
Last active January 26, 2021 07:19
Overview of Web Frameworks (2013)